Skip to main content

Report with Pre-Loaded Parameters


You have a report you want to run in Microsoft Dynamics AX. You’ve already selected the record you want to run the report on, why should you have to select it again on the parameters screen? This guide shows you how to launch your report directly from a button-click without having to manually select report parameters.
Example

Let's assume you already created and deployed your report to AX from Visual Studio. The key is to capture your data that will be used as parameters upon clicking your report button and utilizing inherited methods on your report controller class to auto-populate your parameters.

Your report controller class should extend the SrsReportRunController class:

class BHSTestRC extends SrsReportRunController
{
}


The main method of your report controller class should look similar to this:

public static void main(Args _args)

{
BHSTestRC controller = new BHSTestRC();
BHSDataTable dataTable;

dataTable = _args.record() as BHSDataTable;

controller.parmArgs(_args);
controller.parmReportName(ssrsReportStr(SSRSReportName, Report));
controller.parmShowDialog(false);
controller.startOperation();
}


Above, you're taking the args that were passed into this class, and converting them to the type of table you want to pull data from using the _args.record() function. Then you pass the args into your newly created controller and decide which SSRS report to run.

In order to make the report run without showing the parameter screen, we call controller.parmShowDialog(false). This will disable the parameter screen.

The last line will begin the report. But how does the report know what field to use for what parameter? Use the same report controller class by overwriting the prePromptModifyContract method like this:

protected void prePromptModifyContract()

{
BHSDataTable dataTable;
BHSTestContract contract;

if (this.parmArgs() && this.parmArgs().record())
{

contract = this.parmReportContract().parmRdpContract() as BHSTestContract;

dataTable = this.parmArgs().record();

contract.parmField(dataTable.dataField);
}
}


Above, is another instance of the table you pass in as your args, as well as declare an instance of the report contract class. The contract class houses all the parameters your report will use, as well as parm methods that will access your fields.

Check to see if args were passed in to the class. If so, create an instance of your contract class, and set the args to your data table. Then your parm the data you need from the args you passed in. This step will ensure that you get the correct data into the proper parameter.

The last step shows you how to pass your args into the class in order to use them in the controller. You’ll want to create a new Output menu item that runs your controller class first. Then, on the clicked() method of the button you will use to run your report, place the following code:

Args args = new Args();

args.record(BHSDataTable);

new MenuFunction(menuitemOutputStr(BHSMenuItem), MenuItemType::Output).run(args);


You create a new Args class, and then use the data table to assign a record to args. If you’re on a form and you have a field highlighted in a grid, when you refer to that field, AX will understand that you’re talking about the record that you have highlighted.

From there, create a new MenuFunction using your newly created menu item. At the end we call run(args). This is the action that is responsible for passing the args into your controller class. 
  • Extend SrsReportRunController in your controller class
  • Call controller.parmShowDialog(false) in order to bypass the parameter screen
  • Overwrite the prePromptModifyContract method in order to populate your parameters
  • Create a new menu item that we will use to call into our controller
  • Call menuFunction.run(args) in order to pass our args from our form to our report


HEY HEY HEY!!! HACK OF THE DAY!!                          
You can also use preRunModifyContract()

1)prePromptModifyContract()

Use this method to change the report contract, common use case is to add/change a Query. This method is invoked for interactive scenarios. This method is not invoked for batch scenarios. This means any member variables instantiated in this method will not be available for the lifetime of the controller in batch scenarios.

msdn.microsoft.com/.../srsreportruncontroller.prepromptmodifycontract.aspx

2) preRunModifyContract()

This method is commonly use for Modifying the query. Setting the contract values that are hidden from the user on the dialog.subscribing to rendering Complete event.

msdn.microsoft.com/.../srsreportruncontroller.preRunModifyContract.aspx



Comments

Popular posts from this blog

Edit Method on Form

Edit Method D365 for a form Data Source 1. To create an edit method first create a controller class. with following properties  public static edit MainAccountNum LedgerJournalTransLedger(LedgerJournalTrans _ledgerjournal, boolean _set, MainAccountNum _id) { MainAccountNum accountId = _id; MainAccount mainAccount = MainAccount::findByMainAccountId(_id); if(_set) { if(_ledgerjournal.AccountType== LedgerJournalACType::Ledger) { mainAccount = MainAccount::findByMainAccountId(accountId); if(_ledgerjournal.LedgerDimension) { DimensionDefault defaultDim = LedgerDimensionFacade::getDefaultDimensionFromLedgerDimension(_ledgerjournal.LedgerDimension); _ledgerjournal.LedgerDimension = LedgerDimensionDefaultingEngine::getLedgerDimensionFromAccountAndDim(mainAccount.RecId, DimensionHierarchy::getAccountStructure(mainAccount.RecId), defaultDim); } else { _ledgerjournal.LedgerDimension = LedgerDimensionDefaultingEngine::getLedgerDimensionFromAccountAndDim(mainAccount.RecId, DimensionHierarchy::ge...

Lookup and Mandatory fields on Form using Form event Handlers D365

Lookup and Mandatory fields on Form using Form event Handlers D365 [FormControlEventHandler(formControlStr(VendBankAccounts, VendBankAccount_SLD_BankCode), FormControlEventType::Lookup)] public static void VendBankAccount_SLD_BankCode_OnLookup(FormControl sender, FormControlEventArgs e)     {         Query query = new Query();         QueryBuildDataSource queryBuildDataSource;         FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs;         QueryBuildRange queryBuildRange;         SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(SLD_BankCodes), sender);         sysTableLookup.addSelectionField(fieldNum(SLD_BankCodes, BankCodes));         sysTableLookup.addLookupField(fieldNum(SLD_BankCodes, BankCodes));         sysTableLookup.addLookupField(fieldNum(SLD_BankCode...

Field Level Security In Ax 2012

FIELD LEVEL SECURITY IN AX 2012 In this blog we will discuss field level security applied in  Ax 2012. 1. Field level security is added on form level as well in Ax 2012 its bit different then field level security in D365 2. This also requires privileges to be applied on form specific fields only. Step #1 :  Change datasource property of the field which need to be added in security. Step #2 : Now add these 2 fields in form --- > permissions --- > Read Step #3 : Now finally create privilege and add these fields explicitly in it.       HEY HEY HEY !!!! HACK OF THE DAY  Add Fields in Entry point privilege section of form  Explicitly.