if you look this class \Classes\HcmPositionCopy follow a pattern to run on server the heavier process.
when I tried to make a similar code for my code I had a problem with an inMemory temp table I wanted to pass as parameter. Here my code how I solved using SysTableInMemorySerializer class.
class EF_ClassPack_Trial1
{
//same template as \Classes\HcmPositionCopy
//input parameters
Name name;
EF_ClassPackTmp_Trial1 tmp;
PackedTable packedTmp;
//output parameters
Description descr;
ParametersX packedClass;
#define.CurrentVersion(3)
#localmacro.CurrentList
name,
tmp,
descr,
packedTmp
#endmacro
}
protected static EF_ClassPack_Trial1 construct()
{
return new EF_ClassPack_Trial1();
}
public static EF_ClassPack_Trial1 newTrial()
{
EF_ClassPack_Trial1 cl;
cl = EF_ClassPack_Trial1::construct();
return cl;
}
public Name parmName(Name _name = name)
{
name = _name;
return name;
}
public EF_ClassPackTmp_Trial1 parmTmp(EF_ClassPackTmp_Trial1 _tmp = tmp)
{
EF_ClassPackTmp_Trial1 tmp1;
if (prmisDefault(_tmp))
SysTableInMemorySerializer::unpackTable(packedTmp, tmp1);
else
packedTmp = SysTableInMemorySerializer::packTable(_tmp);
return tmp1;
}
public Description parmDescr(Description _descr = descr)
{
descr = _descr;
return descr;
}
public void run()
{
startLengthyOperation();
packedClass = EF_ClassPack_Trial1::runOnServer(this.pack());
endLengthyOperation();
}
public client server static EF_ClassPack_Trial1 create(container _packedClass)
{
EF_ClassPack_Trial1 cl = EF_ClassPack_Trial1::construct();
cl.unpack(_packedClass);
return cl;
}
public container pack()
{
return [#CurrentVersion, #CurrentList];
}
public boolean unpack(container _packedClass)
{
Integer version = conPeek(_packedClass,1);
switch (version)
{
case #CurrentVersion:
[version, #CurrentList] = _packedClass;
break;
default:
return false;
}
return true;
}
public EF_ClassPack_Trial1 getRunOutput()
{
return EF_ClassPack_Trial1::create(packedClass);
}
public static server container runOnServer(container _packedClass)
{
EF_ClassPack_Trial1 cl = EF_ClassPack_Trial1::create(_packedClass);
cl.doSomeOperation();
return cl.pack();
}
private void doSomeOperation()
{
Counter tmpCount;
tmp = this.parmTmp();
select count(RecId) from tmp;
tmpCount = int642int(tmp.RecId);
descr = strFmt('ciao %1 - tot: %2', name, tmpCount);
}
public static void main(Args _args)
{
EF_ClassPack_Trial1 cl;
//EF_ClassPack_Trial1 clOptput;
EF_ClassPackTmp_Trial1 tmp;
tmp.Field1 = 'ciao';
tmp.insert();
tmp.Field1 = 'ciao1';
tmp.insert();
cl = EF_ClassPack_Trial1::newTrial();
cl.parmName('Giorgio');
cl.parmTmp(tmp);
cl.run();
//clOptput = cl.getRunOutput();
//info(clOptput.parmDescr());
info(cl.getRunOutput().parmDescr());
}
No comments:
Post a Comment