Passing Arguments to a Data Provider Class in Dynamics AX
Many Dynamics AX reports utilize Data Provider classes, so when modifying existing reports or creating new ones, there is often a need to pass information to the DP class from the report controller class. Here is a simple example of how this can be done.
In this example, the customer has two menu items on a form calling the same report, and the report needs the information about which menu item the user selected.
First we need a new parm method on the data contract so that we can set the value from the controller class and later retrieve it in the DP class.
public UserMenuSelection parmOutputSelection(str _outputSelection = outputSelection) { outputSelection = _outputSelection; return outputSelection; }
The DataMemberAttribute attribute identifies our parm method as a member of the data contract.
As is usually the case, the report controller class is called from the Output Menu Item and since Args is passed to the Main() method we can utilize Args().MenuItemName to retrieve the user’s selection as in the screen shot below…
Finally, from the DP class we can simply instantiate the contract and get the value…
Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.
Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.