How to implement Runbase form in AX

How to implement Runbase form in AX

MCP · Azure DevOpsYour delivery board, readable by an agentMCP · DataverseOne consent, and the data layer opensMCP · Dynamics 365 F&OConnecting F&O to an agent Microsoft hasn’t documented
Today I had a requirement that allow users to run Outlook synchronization process in batch rather sync it manually using out of the box functionality. Let's have a look on existing functionality and then extend it to achieve the requirement of running it in batch.

Existing functionality in AX

Home> Periodic > Synchronize [AOT form name is smmOutlookSyncrhonization]

As you can see someone has to manually sync outlook emails to AX acvitities or viceversa.

Extended functionality in AX

Let's implement this functionality in batch so users can set recurrence the Sync.

Create a new class;
Code
class SyncOutLookEmails_RunbaseForm extends RunBaseBatch
{
    // Packed
    TransDate            testDate; // I am using this variable for own testing purpose
    #define.CurrentVersion(2)
    #define.Version1(2)
    #localmacro.CurrentList
        testDate
    #endmacro

}
Code
public Object dialog()
{
    DialogRunbase   dialog = Dialog::newFormnameRunbase(formstr(smmOutlookSyncrhonization),this);
;
    return dialog;
}
Code
public boolean getFromDialog()
{
    boolean ret;
    ret = super();
    return ret;

}
Code
protected void new()
{
    super();
}
Code
public container pack()
{
    return [#CurrentVersion,#CurrentList];
}
Code
public boolean runsImpersonated()
{
    return true;

}
Code
public boolean showQueryValues()
{
    return true;
}
Code
public boolean unpack(container _packedClass)
{
    boolean     ret;
    Version     version = RunBase::getVersion(_packedClass);
    ;
    switch (version)
    {
        case #CurrentVersion:
            [version, #CurrentList] = _packedClass;
            ret = true;
            break;
        default:
            ret = false;
            break;
    }
    return ret;
}
Code
server static SyncOutLookEmails_RunbaseForm construct()
{
    return new SyncOutLookEmails_RunbaseForm();
}
Code
server static void main(Args args)
{
    SyncOutLookEmails_RunbaseForm   syncOutLookEmails_RunbaseForm = SyncOutLookEmails_RunbaseForm::construct();
    if (syncOutLookEmails_RunbaseForm.prompt())
        syncOutLookEmails_RunbaseForm.run(); 
}
Run this class by pressing F5, Ooopsss!!! it throws an error

A DialogStartGrp group is missing from the form smmOutlookSyncrhonization. In this group dialog controls are added.
This requires to add a group on the form and this has to have under a tab/tab page, let's do this;
How the current form looks in AOT


How it should look like to use it for batch class, created above.


  • Added new Tab
  • Added new Tab page
  • Added dialogStartGrp under tab page
  • Moved exisiting groups under tab page
  • Set caption "General" to tab page.
It requires few more methods at form level to make it working in batch

Code
public class FormRun extends ObjectRun
{
    HcmWorker                   hcmWorker;
    OutlookUserSetup            outlookUserSetup;
    TransDate                   synchronizeFromDate;
    TransDate                   synchronizeToDate;
   
    SyncOutLookEmails_RunbaseForm   syncOutLookEmails_RunbaseForm;
}

public void init()
{
    synchronizeFromDate = systemdateget();
    synchronizeToDate = systemdateget();
   
    syncOutLookEmails_RunbaseForm = element.args().caller().runbase();

    super();

    if (!smmAxaptaOutlookMapping::isOutlookMappingSetupCompleted())
    {
        smmAxaptaOutlookMapping::createDefaultSetup();
    }

    // Find worker connected to the current logged ion
    hcmWorker = HcmWorker::find(HcmWorker::userId2Worker(curuserid()));

    if (hcmWorker)
    {
        outlookUserSetup = OutlookUserSetup::findByWorker(hcmWorker.RecId);
        // Calculate synchronization period based on the employee setup parameters
        activityFromDate.dateValue(systemdateget() - outlookUserSetup.SmmSynchronizeDaysBack);
        activityToDate.dateValue(systemdateget() + outlookUserSetup.SmmSynchronizeDaysForward);
    }
    else
    {
        // No employee is mapped to the current user. Set mapping in Employee option form.
        error("@SYS80637");
        element.close();
    }
}

void closeOk()
{
    DialogRunbase dialog = element.args().caller();
;
    dialog.updateServer();
    if (syncOutLookEmails_RunbaseForm.checkCloseDialog())
        super();
}

//AOSRunMode::Client
RunBase runBase()
{
    return syncOutLookEmails_RunbaseForm;
}
Run class again by pressing F5


Target achieved!!! You can run the form with batch


Happy Dax!ng !!!
Previous article← AX 7 Development introduction exam available now
Discussion

Ask a question or leave feedback

This is a review interaction. The WordPress version will store, thread and moderate comments.

Thanks — submitted for moderation in this review.
Search the whole site · Ctrl/⌘ + K