Thursday 5 December 2013

AX2012 SSRS Multi Value Ax Enum Provider Parameters

An anticipated major bonus with AX2012 reports was the Enum Provider, but in practice it seems that it’s not possible to have a Multi Value parameter of any type other than a string? I’ve tried almost everything I could think of to be able to pass arrays of integers but always get null returns, so…

So here are examples of how Microsoft handles it (hard coding) and two alternative solutions until I can find a cleaner solution as in our business Enums historically evolve and change so reports need to remain dynamic.

I’m hoping someone has a more efficient way of achieving this?

Microsoft Solution

Microsoft seems to have adopted the following approach in the out of the box reports which effectively hard codes the list of enum values in the report and corresponding RPD class:

Class > ProjValCategoryDP.processReport
(projFixedPrice && projTable.Type == ProjType::FixedPrice)  ||
(projInternal   && projTable.Type == ProjType::Internal)


Where projFixedPrice and projInternal are NoYes Enums obtained via the contract class from hard coded parameters of type Boolean in the report. Even the prompt String is hard coded instead of using a label:
 
 

 This results in a huge list of parameters without the select all functionality you gain from using a standard Multi Value dropdown:

 
 

Alternative Solution 1

This method uses the standard Microsoft AX Enum Provider and handling all the logic in the RDP class that processes the report.

Create a DataSet with source type AX Enum Provider and select the Enum in the query you wish to use:
 


In the values property on the parameter use the Name for the value field not the Value as that is an integer which causes the problem when Multi Value property is set to true:
 


Resulting in a standard Multi Value select dropdown:
 

 
In your Contract class you can specify the AifCollectionTypeAttribute to be an array of Types::String which seems to be the only supported type for Multi Value parameters passed to an RDP class:


Now in your Data Provider class you can look up the value of the Enum from the array of passed names:


Notes
  • ListEnumerator.current returns a data type of anytype which does not automatically convert when using DictEnum.symbol2Value so any2str is required unless it’s cast into a string first where it would be automatic but more lines of code.
  • DictEnum.symbol2Value looks up the value based on the Name, the misleading DictEnum.name2Value looks up based on the Label.


Alternative Solution 2

To reduce the effort of handling the all logic in the RDP class, instead of using the Enum Provider create a RDP class to handle the majority of the logic passing the Enum value as a string so in your main RDP class that processes the report logic you only need to convert from a string to an integer with a hidden parameter for the Enum name for reusability of the RDP Class.

Create a tempDB table for your RDP return > TMPenumValues


EnumLookupContract Class declaration and one method:

EnumLookupDP Class declaration and two methods:


In your SSRS report you can add a new RDP Data Set for the Enum parameter. Set the properties of the enumName parameter to hidden and the Values to non-queried setting the value to the Enum name you wish to use.

In the values property on the parameter on your main RDP class you wish to add the Multi Value Enum parameter use the ValueStr for the value field and Label.









Now in your main RDP class for processing the report you can look up the value of the Enum from the array of passed value strings by just doing the conversion of string to integer without need to use the DictEnum class to lookup value from the name: