[ExtensionOf(classStr(SysUserLogCleanup))] final class SysUserLogCleanup_Extension { // static members static private SysUserLogCleanup myRunningInstance; // Extending class state... private boolean myArchive; private DialogField myDialogArchive; #define.CurrentVersion(1) #localmacro.CurrentList myArchive #endmacro // Adding new instance methods private void extDialog(Dialog _dialog) { myDialogArchive = _dialog.addField(extendedtypestr(NoYesId), "Archive"); myDialogArchive.value(myArchive); } private void extGetFromDialog() { myArchive = myDialogArchive.value(); } private boolean extUnpack(container packedClass) { Integer version = RunBase::getVersion(packedClass); switch (version) { case #CurrentVersion: [version, #currentList] = packedClass; break; default: return false; } return true; } private container extPack() { return [#CurrentVersion, #CurrentList]; } private void extInitParmDefault() { myArchive = true; } private void extArchiveUserLog(SysUserLog _userLog) { if (myArchive) { //... } } // Wiring up event handlers... [PostHandlerFor(classStr(SysUserLogCleanup), methodStr(SysUserLogCleanup, dialog))] public static void SysUserLogCleanup_Post_Dialog(XppPrePostArgs _args) { Dialog dialog = _args.getReturnValue(); SysUserLogCleanup instance = _args.getThis() as SysUserLogCleanup; instance.extDialog(dialog); } [PostHandlerFor(classStr(SysUserLogCleanup), methodStr(SysUserLogCleanup, getFromDialog))] public static void SysUserLogCleanup_Post_GetFromDialog(XppPrePostArgs _args) { SysUserLogCleanup instance = _args.getThis() as SysUserLogCleanup; instance.extGetFromDialog(); } [PostHandlerFor(classStr(SysUserLogCleanup), methodStr(SysUserLogCleanup, pack))] public static void SysUserLogCleanup_Post_pack(XppPrePostArgs _args) { SysUserLogCleanup instance = _args.getThis() as SysUserLogCleanup; //Also pack the extension instance.packExtension(_args, classStr(MySysUserLogCleanup_Extension), instance.extPack()); } [PostHandlerFor(classStr(SysUserLogCleanup), methodStr(SysUserLogCleanup, unpack))] public static void SysUserLogCleanup_Post_unpack(XppPrePostArgs _args) { SysUserLogCleanup instance = _args.getThis() as SysUserLogCleanup; container myState = instance.unpackExtension(_args, classStr(MySysUserLogCleanup_Extension)); //Also unpack the extension if (!instance.extUnpack(myState)) { //Extension couldn't be unpacked - return false to trigger initParmDefault() gets called _args.setReturnValue(false); } } [PostHandlerFor(classStr(SysUserLogCleanup), methodStr(SysUserLogCleanup, initParmDefault))] public static void SysUserLogCleanup_Post_initParmDefault(XppPrePostArgs _args) { SysUserLogCleanup instance = _args.getThis() as SysUserLogCleanup; instance.extInitParmDefault(); } [PreHandlerFor(classStr(SysUserLogCleanup), methodStr(SysUserLogCleanup, run))] public static void SysUserLogCleanup_Pre_run(XppPrePostArgs _args) { //Store a static reference, so we can call it from SysUserLog_onDeleting. myRunningInstance = _args.getThis() as SysUserLogCleanup; } [PostHandlerFor(classStr(SysUserLogCleanup), methodStr(SysUserLogCleanup, run))] public static void SysUserLogCleanup_Post_run(XppPrePostArgs _args) { //Running complete myRunningInstance = null; } // Wiring up event handler for deletion of the record [DataEventHandler(tableStr(SysUserLog), DataEventType::Deleting)] static public void SysUserLog_onDeleting(Common _sender, DataEventArgs _e) { if (runningInstance) { myRunningInstance.extArchiveUserLog(_sender as SysUserLog); } } }
DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.
Authors are allowed to set their own AdSense units and "buy me a coffee" link.
Join us.