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

By Taylor Valnes | August 9, 2019

Ui builder class not using the same contract as controller and dp classes in dynamics ax 2012

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.

Related Posts

Recommended Reading:

5.27.22 Dynamics GP

How to Run Drop Ship Sales in Dynamics GP

Need to Invoice the Customer before you get the invoice from the vendor? This The freight forwarder has contacted you […]

Read the Article

New Features in Dynamics 365 Business Central 2022 Wave 1 Release – Protecting G/L Accounts From Being Deleted

There are a lot of exciting New Features in Dynamics 365 Business Central 2022 Wave 1 Release to get excited […]

Read the Article
5.25.22 Financials

Rounding Numbers in Power Automate

  If you’ve ever tried to round numbers in Power Automate, you have probably already run into the issue there […]

Read the Article

Manage U.S. Use Tax on Purchase Orders in Dynamics 365 Finance and Operations

  Managing sales tax requirements on your business purchase can be complicated, but Dynamics 365 Finance and Operations can help […]

Read the Article
5.19.22 Dynamics CRM

How to Write a Great Support Ticket in the Stoneridge Support Portal

Submitting a support ticket through the Stoneridge Support Portal is a quick and effective way to get assistance for any […]

Read the Article

Managing Your Business Through Uncertain Times Using Dynamics 365 Finance and Operations

  Dynamics 365 Finance and Operations (F&O) can help you make informed decisions on how to move your business forward. […]

Read the Article
5.13.22 Power Platform

Using Power BI Object Level Security

  The following article will demonstrate how to use Power BI Object Level Security to disable column data based on […]

Read the Article
5.12.22 Dynamics CRM

How to Use the Stoneridge Support Portal

Stoneridge Software’s support portal is an intuitive and useful function that makes it easy for you to access resources to […]

Read the Article
5.6.22 Dynamics GP

Dynamics GP Transaction Removal: Purchase Orders

  Are you having performance issues with Purchase Orders?  Do you find that there are old Purchase Orders on your […]

Read the Article

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