Extending SysOperation contracts with DataMemberAttribute

Extending SysOperation contracts with DataMemberAttribute

Since January 2019, it has become possible to decorate new “parm” methods on extension classes with “DataMember” attributes. In other words, it is now feasible to add a new parameter onto a dialog window of a standard class, even if this class was implemented within the SysOperation framework.
This was enabled by the so-called “4th extension wave” in Platform update 23.

Before PU 23, the below code


[ExtensionOf(ClassStr(AssetRollForwardContract))]
final class AssetRollForwardContract_Extension
{
private boolean updateDeprInfo;
[DataMemberAttribute(identifierStr(AssetAdditionalAcqDepreciation))]
public boolean parmUpdateDeprInfo(boolean _updateDeprInfo = updateDeprInfo)
{
updateDeprInfo = _updateDeprInfo;
return updateDeprInfo;
}
}
did not compile but brought up the error message “DataMemberAttributeOnExtensionClassNotSupported: The DataMemberAttribute is not supported on extension classes.

Now it works, and the new parameter is plugged in nicely at the desired place:
SysOperationUI dialog

Initializing the parameters with default values posed a challenge. As suggested by Mr. DrĂ¡b here, the class should be declared with the SysOperationInitializable interface, and amended by an initialize() method. However, if the original class did not implement SysOperationInitializable, your extension cannot do any better.
The only solution that worked was simple as a brick: an inline assignment of the respective field variable (which is another feat in X++, quite a new one):

[ExtensionOf(ClassStr(AssetRollForwardContract))]
final class AssetRollForwardContract_Extension
{
private boolean updateDeprInfo = true;
[
DataMemberAttribute(identifierStr(AssetAdditionalAcqDepreciation)),
SysOperationLabelAttribute(literalstr("@SYS4080213")),
SysOperationHelpTextAttribute(literalstr("@SYS321607")),
SysOperationDisplayOrderAttribute('4')
]
public boolean parmUpdateDeprInfo(boolean _updateDeprInfo = updateDeprInfo)
{
updateDeprInfo = _updateDeprInfo;
return updateDeprInfo;
}
}

The parameter becomes active by default, but the last value selected by the user is still serialized and de-serialized nicely, right as it should be.