SysOperation job template

Contract with a query:

/// <summary>
/// The <c>VKCustMarketingClearDataContract</c> contract for the job to clear customer marketing information.
/// </summary>
[DataContractAttribute]
class VKCustMarketingClearDataContract
{
    str encodedQuery;

    [DataMemberAttribute, AifQueryTypeAttribute('_encodedQuery', queryStr(VKCustMarketingQuery))]
    public str parmQuery(str _encodedQuery = encodedQuery)
    {
        encodedQuery = _encodedQuery;

        return encodedQuery;
    }

}
To state UIBuilder class, data contract attributes should be changed:
[
    DataContractAttribute,
    SysOperationContractProcessingAttribute(classStr(VKCustMarketingClearUIBuilder))
]
If validation is required, then the data contract should implement SysOperationValidatable
class VKCustMarketingClearDataContract implements SysOperationValidatable
and additional validation method implemented:
 /// <summary>
 /// Determines whether the parameters are valid.
 /// </summary>
 /// <returns>
 /// true when the parameters are valid; otherwise, false.
 /// </returns>
 public boolean validate()
 {
     boolean isValid = true;
     if (!dateFrom)
     {
         isValid = checkFailed(strFmt("@SYS84753", "@SYS180311"));
     }
     if (!dateTo)
     {
         isValid = checkFailed(strFmt("@SYS84753", "@SYS180217"));
     }
     if (dateFrom > dateTo)
     {
         isValid = checkFailed(strFmt("@SYS300457", date2StrUsr(dateFrom, DateFlags::FormatAll), date2StrUsr(dateTo, DateFlags::FormatAll)));
     }
     return isValid;
 }
parm method attributes, you can review all of them starting from SysOperation*
SysOperationLabel("@VK:Labelid")
SysOperationLabel(literalStr("Hardcoded label"))
SysOperationHelpText("@VK:Labelid")
SysOperationDisplayOrder('1')
SysOperationControlVisibility(false)

Controller:

/// <summary>
/// The <c>VKCustMarketingClearController</c> controller for the job to clear customer marketing information.
/// </summary>
class VKCustMarketingClearController extends SysOperationServiceController
{
    public ClassDescription caption()
    {
        ClassDescription ret;

        ret = "@VK:ClearUnregisteredEmailAddresses";

        return ret;

    }

    public LabelType parmDialogCaption(LabelType _dialogCaption = "")
    {
        LabelType caption;

        caption = "@VK:ClearUnregisteredEmailAddresses";

        return caption;
    }

    public static VKCustMarketingClearController construct()
    {
        return new VKCustMarketingClearController();
    }

    public void getFromDialog()
    {
        //FormComboBoxControl mainAccountControl;
        //DialogForm                          theDialogForm;
        VKCustMarketingClearDataContract   contract;


        //theDialogForm = this.dialog().dialogForm();

        super();

        //mainAccountControl = theDialogForm.runControl(#MainAccount);

        contract = this.getDataContractObject(classStr(VKCustMarketingClearDataContract));


        if (contract)
        {
            // Set the values in data contract
            //contract.parmMainAccount(mainAccountControl.text());
        }
    }

    public static void main(Args args)
    {   
        VKCustMarketingClearController             controller;
        identifierName                              className;   
        identifierName                              methodName;
        SysOperationExecutionMode                   executionMode;
   
        [className, methodName, executionMode] = SysOperationServiceController::parseServiceInfo(args);

        controller = new VKCustMarketingClearController(className, methodName, executionMode);

        if (controller.prompt())
        {
            controller.run();
        }
    }

}

Service:

/// <summary>
/// The <c>VKCustMarketingClearService</c> the job to clear customer marketing information.
/// </summary>
class VKCustMarketingClearService
{

    /// <summary>
    /// Clears unregistered customer email addresses
    /// </summary>
    /// <param name="_contract">
    /// Job contract, contains query of records, which should be deleted
    /// </param>
    public void clearCustMarketing(VKCustMarketingClearDataContract _contract)
    {
        Query               q = new Query(SysOperationHelper::base64Decode(_contract.parmQuery()));
        QueryRun            qr= new QueryRun(q);
        VKCustMarketing    custMarketing;
        int                 recordsDeleted;

        ttsbegin;
        while (qr.next())
        {
            custMarketing = qr.get(tableNum(VKCustMarketing));
            custMarketing.selectForUpdate(true);
            custMarketing.delete();
            recordsDeleted++;
        }

        info(strfmt("@VK:NonRegCustRecordsDeleted", recordsDeleted));
        ttscommit;
    }

}

Action Menu Item:
Enum Type Parameter: SysOperationExecutionMode
Enum Parameter: Synchronous
Object Type: Class
Object: VKCustMarketingClearController (controller class)
Parameters: VKCustMarketingClearService.clearCustMarketing (service method to run)

UIBuilder

Optional, with lookup example and mandatory dialogue fields:
class VKCustMarketingClearUIBuilder extends SysOperationAutomaticUIBuilder
{

    public void postBuild()
    {
        super();

        DialogField dlgFieldInterfaceId;
        dlgFieldInterfaceId = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(VKCustMarketingClearDataContract, parmInterfaceId));
        // make field appear as mandatory
        dlgFieldInterfaceId.fieldControl().mandatory(true);
        // overwrite lookup method
        dlgFieldInterfaceId.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(VKCustMarketingClearUIBuilder, interfaceIdLookup), this);

        DialogField dlgFieldRetentionDays;
        dlgFieldRetentionDays = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(VKCustMarketingClearDataContract, parmRetentionDays));
        dlgFieldRetentionDays.fieldControl().mandatory(true);
    }

    public void interfaceIdLookup(FormControl _formControl)
    {
        //VKInterfaceSetup::lookupInterfaceId(_formControl);
        // Better implement lookup as a table method and then re-use from all places
        Query query = new Query();
        QueryBuildDataSource queryBuildDataSource = query.addDataSource(tableNum(VKInterfaceSetup));
     
        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(VKInterfaceSetup), _formControl);
     
        sysTableLookup.addLookupField(fieldNum(VKInterfaceSetup, InterfaceId), true);
        sysTableLookup.addLookupField(fieldNum(VKInterfaceSetup, InterfaceDescription));
        sysTableLookup.addLookupField(fieldNum(VKInterfaceSetup, InterfaceDirection));
    
        sysTableLookup.parmQuery(query);
     
        sysTableLookup.performFormLookup();
    }

}

If you want to automatically build dialog based on the data contract, then UIBuilder should extend SysOperationAutomaticUIBuilder. If you want to build it manually, then extend from SysOperationUIBuilder


 

Search

About

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.
Join us.

Blog Tags