SSRS Report contract class in Ax 2012

Description:-

Report contracts in AX 2012 are used for defining parameters to the SSRS report. We can define any number of parameters using X++ statements of any data type, which can be passed on to the RDP class. And then, we can use the same contracts to query data from the database engine which will decrease an overhead on execution of a query in SQL.

If you have a validation method in your contract class then you have to implements SysOperationValidatable in your contract class like below syntax.

To define a Report contract class we use the following syntax:

[DataContractAttribute]
class ItemTransactionSummaryContract implements SysOperationValidatable
{
    List  ItemGroupIdList,ListItemId;
    BaseDate FromDate,ToDate;
    NoYesId   IsDiamension;
}

If you are using UI Builder class then you have to mansion UI Builder class in contract class like below.

[DataContractAttribute,
    SysOperationContractProcessingAttribute(classstr(ItemTransactionSummaryUIB))]
class ItemTransactionSummaryContract implements SysOperationValidatable
{
    List      ItemGroupIdList,ListItemId;
    BaseDate  FromDate,ToDate;
    NoYesId   IsDiamension;
}

Below are different methods which I have used in my contract class.

[DataMemberAttribute("From Date"),
SysOperationLabelAttribute("From Date"),
SysOperationDisplayOrderAttribute('1')]
public BaseDate ParmFromDate(FromDate _FromDate = FromDate)
{
    FromDate = _FromDate;
    return     FromDate;
}

[DataMemberAttribute("To Date"),
SysOperationLabelAttribute("To Date"),
SysOperationDisplayOrderAttribute('2')]
public BaseDate ParmToDate(ToDate _ToDate = ToDate)
{
    ToDate = _ToDate;
    return   ToDate;
}

[DataMemberAttribute("Item Group"),
    AifCollectionTypeAttribute("Item Group", Types::String),
    SysOperationLabelAttribute(literalStr("Item Group"))]
public List parmItemGroup(List _ItemGroupIdList = ItemGroupIdList)
{
    ItemGroupIdList = _ItemGroupIdList;
    return            ItemGroupIdList;
}

[DataMemberAttribute("Item Id"),
    AifCollectionTypeAttribute("Item Id", Types::String),
    SysOperationLabelAttribute(literalStr("Item Id"))]
public List parmItemId(List _ListItemId = ListItemId)
{
    ListItemId = _ListItemId;
    return       ListItemId;
}

[DataMemberAttribute,
SysOperationLabelAttribute("Diamension")]
public NoYesId parmDiamension(NoYesId _IsDiamension = IsDiamension)
{
    IsDiamension = _IsDiamension;
    return         IsDiamension;
}

You can create validate method for validate the report parameter like below. In my case I have ItemGroupId, ItemId, FromDate and ToDate. I have below validation in my validation method.

1)      FromDate should not be empty.
2)      ToDate should not be empty.
3)      FromDate should not be greater than ToDate.
4)      ItemGroupId and ItemId should not be empty.
ItemGroupId and ItemId both should not be selected.

public boolean validate()
{
    boolean         isValid = true;
    List            ItemGroupList = new List(Types::String);
    List            ItemIdList = new List(Types::String);
    
    ItemGroupList   = this.parmItemGroup();
    ItemIdList      = this.parmItemId();

    if(!ItemGroupList.elements() && !ItemIdList.elements())
    {
        isValid = checkFailed("ItemGroupId and ItemId both should not be empty");
    }
    if(ItemGroupList.elements() && ItemIdList.elements())
    {
        isValid = checkFailed("ItemGroupId and ItemId both should not be selected");
    }
    if (!FromDate)
    {
        isValid = checkFailed("From Date should be entered");
    }
    if (!ToDate)
    {
        isValid = checkFailed("To Date should be entered");
    }
    if (isValid && (FromDate > ToDate))
    {
        isValid = checkFailed(strfmt("From Date should be less than or equal to To Date", 
                  date2StrUsr(fromDate, DateFlags::FormatAll), date2StrUsr(toDate, DateFlags::FormatAll)));
    }
    return isValid;
}

Related Posts

Previous
Next Post »

2 comments

comments
September 7, 2020 at 7:05:00 PM GMT+5:30 delete

Which Attribute use for set default value to parameter, for example create base enum male or female , I want to display Enum value as Female first if user want they can change to male but first time dialogue generate I
need Female as parameter

Reply
avatar
June 5, 2021 at 10:21:00 PM GMT+5:30 delete

To pass default value to parameter using SSRS Class in axapta 2012 you can override method prePromptModifyContract in controller class then initialize contract class variable then you can pass value using contract class method calling

Reply
avatar

Thanks for comments.....