UI Builder Class Not Using the Same Contract as Controller and DP Classes in Dynamics AX 2012

By Taylor Valnes | August 9, 2019

The other day I had to convert a custom query-based SSRS report within Dynamics AX 2012 into a regular report so that we could run the report from a different form (ProdTable & ProdTableListPage) and have certain values auto-populate the query prompt. Normally something like this would be easy to implement, however, I ran into some issues when making the modifications.

I created the data provider, Contract and Controller classes, and the dialog values were not changing. I ended up building a UI Builder class as well to counteract this issue. I had the logic to pre-populate the contract in the controller class by using the record that was highlighted, and I verified that the values were being pulled into the contract class as desired. I then stumbled across the issue of the UI Builder class was not using the same contract instance as the Controller & Data Provider classes. This was resulting in the values not populating the prompt and was not being passed to the Data Provider class. What I wound up having to do is to move my logic into the UI Builder class. Below I have provided the code I created in order to utilize this.

Controller main method:

public static void main(Args _args)
{
    SSI_DemoController controller = new SSI_DemoController();
    SSI_DemoContract contract = new SSI_DemoContract();

    controller.parmReportName(ssrsReportStr(SSI_DemoReport, Report));
    controller.parmArgs(_args);
    controller.parmShowDialog(true);
    controller.parmShowReportViewerParameters(false);

    controller.startOperation();
}

The rest of the logic had to be put into the UI Builder class, specifically the build method.

public void build()
{
    DialogField dlgItem;
    Args args;
    ProdTable prodTable;
    SRSPrintDestinationSettings printSettings;
    controllerDlg = this.controller();
    contract = this.dataContractObject();
    args = controllerDlg.parmArgs();

    controllerDlg.parmReportContract().parmRdpContract(contract);

    if(args.record() && args.record().TableId == tableNum(ProdTable))
    {
        prodTable = args.record();
        contract.parmItemId(prodTable.ItemId);
        contract.parmNumberOfCopies(prodTable.QtyCalc);
    }

    printSettings = controllerDlg.parmReportContract().parmPrintSettings();
    printSettings.printMediumType(SRSPrintMediumType::Printer);
    if(contract.parmNumberOfCopies() != 0)
    {
        printSettings.overridePageSettings(true);
        printSettings.overridePrintContractSettings(true);
        printSettings.numberOfCopies(contract.parmNumberOfCopies());
    }

    dlgItem = this.addDialogField(methodStr(SSI_DemoContract,parmItemId),contract);

    dlgItem = this.bindInfo().getDialogField(contract,methodStr(SSI_DemoContract,parmItemId));
}

This code was able to solve the issue I was having and should help you if you’re facing the same problems. Learn more tips for Dynamics AX 2012 by subscribing to our blog. If you have any questions in the meantime, please reach out to the experts at Stoneridge Software.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!

X