Thursday, May 3, 2012

Creating multi-select lookup dialog for SSRS report parameter in MS Dynamics AX 2012

Hello All,
I just recently found a way to create a multi select lookup
dialog for SSRS report parameter using SysLookupMultiSelectGrid
class. I thought it might be helpfull for other developers
as well since I couldn't find any other Blog or Post answering this issue.

I am just assuming that you know how to create a simple dialog
for reporting parameter. However, if you don't know this link might be helpfull to you. http://www.artofcreation.be/2011/08/22/ax2012-sysoperation-part-1-data-contracts-and-service-operations/

I will just write those methods which will create a multi select
dialog. So, here we go.

Step 1:
In your data contract class declaration method, define your
parameter with 'List'. For example I want to create a multi select dialog for
customers in which I need Customer account to be selected when a user selects
any customer. SO, I will write

List accountNum;
In your DataMemberAttribue method type
the following code

[
DataMemberAttribute('AccuontNum'),
AifCollectionTypeAttribute('AccountNum', Types::String),
SysOperationLabelAttribute(literalstr("@SYS302"))
]
public List parmAccountNum(List _accountNum = accountNum)
{
accountNum = _accountNum;
return accountNum;
}
Your screen will look like this

Step 2:
Now that you have completed the contract class, let’s move on to
the UI Builder class. In your main lookup method write the following code.

public void
lookup(FormStringControl _control)
{
Query query = new Query(queryStr(CustTableSRS));
container cnt;
SysLookupMultiSelectGrid::lookup(query, _control, _control, cnt);
}
you may have to create 3 more methods to run your code without any
error. They are getFromDialog, initializeFields
and postRun. Here is the code for these methods. you have to change the contract class name with your
contract class

First create a new mothod for initializeFields and paste the following code
public void
initializeFields()
{
custMultiSelectContract contract = this.dataContractObject();
}
Then create another method for getFromDialog
public void getFromDialog()
{
custMultiSelectContract contract = this.dataContractObject();
super();
}
and then another method for postRun
public void postRun()
{
custMultiSelectContract contract = this.dataContractObject();
}
That's it. You are now done. Run your report and enjoy.
Thanks.

6 comments:

  1. Very useful... do you know if there is a way of passing Types::Integer as can only seem to get Strings to pass in Multi Value parameters?

    Problem/dirty workaround here http://ueberax.blogspot.co.uk/

    ReplyDelete
  2. If you have multiple SysLookupMultiSelectGrid controls how do you override the lookup methods for them, so they each display the results of a specific query. It appear you cannot use AifCollectionTypeAttribute in the Contract class with dialogField.registerOverrideMethod(methodstr(FormStringControl, lookup),..... as this complains you are trying to override the lookup method twice.

    ReplyDelete
  3. I am doing the same thing but I am not able to display all records i multi select the dialog field of sales id but I am only able to see the record of only one sales id


    ReplyDelete
  4. Please revert back as soon as possible

    ReplyDelete
  5. Can you please post the contract class definition as well

    ReplyDelete