I have a class that implements SysPackable. When I extend this class I want also to extend the list of variables in the macro.
Note: in Ax 2012 you don’t have SysPackExtensions.
otherwise see here: https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/extensibility/extend-runbase-class
class EF_SysPackableTrial implements SysPackable
{
Description description;
str myString;
#define.CurrentVersion(1)
#define.version1(1)
#localmacro.CurrentList
description,
myString
#endmacro
}
public container pack()
{
return [#CurrentVersion, #CurrentList];
}
public boolean unpack(container packedClass)
{
int version = runbase::getVersion(packedClass);
switch (version)
{
case #CurrentVersion:
[version,#CurrentList] = packedClass;
return true;
default :
return false;
}
return false;
}
public static EF_SysPackableTrial create(container _pack)
{
EF_SysPackableTrial cl = new EF_SysPackableTrial();
cl.unpack(_pack);
return cl;
}
public Description parmDescription(Description _description = description)
{
description = _description;
return description;
}
public str parmMyString(str _myString = myString)
{
myString = _myString;
return myString;
}
in the extend class I modified the pack and unpack methods
class EF_SysPackableTrialExtend extends EF_SysPackableTrial
{
Name name;
#define.CurrentVersion(1)
#define.version1(1)
#localmacro.CurrentList1
name
#endmacro
}
public container pack()
{
container ret;
ret = [#CurrentVersion, [#CurrentVersion, #CurrentList], [#CurrentVersion, #CurrentList1]];
return ret;
}
public boolean unpack(container packedClass)
{
int version = SysOperationHelper::getVersion(packedClass);
switch (version)
{
case #CurrentVersion:
[version,#CurrentList] = conPeek(packedClass,2);
[version,#CurrentList1] = conPeek(packedClass,3);
return true;
default :
return false;
}
return false;
}
public static EF_SysPackableTrialExtend create(container _pack)
{
EF_SysPackableTrialExtend cl = new EF_SysPackableTrialExtend();
cl.unpack(_pack);
return cl;
}
public Name parmName(Name _name = name)
{
name = _name;
return name;
}
and here a simple job to prove it works fine:
static void EF_SysPackableTrialExtend(Args _args)
{
EF_SysPackableTrialExtend EF_SysPackableTrialExtend, sysPackableTrial1;
EF_SysPackableTrialExtend = new EF_SysPackableTrialExtend();
EF_SysPackableTrialExtend.parmDescription('ciao1');
EF_SysPackableTrialExtend.parmMyString('ciao2');
EF_SysPackableTrialExtend.parmName('pp');
sysPackableTrial1 = EF_SysPackableTrialExtend::create(EF_SysPackableTrialExtend.pack());
info(sysPackableTrial1.parmDescription());
info(sysPackableTrial1.parmMyString());
info(sysPackableTrial1.parmName());
}
I posted this sample also on the forum https://community.dynamics.com/ax/f/microsoft-dynamics-ax-forum/380610/extensions-extend-a-macro-without-overlay---pack-unpack-in-ax-2012
No comments:
Post a Comment