For RDP data contracts, implement the validate method and return True or False to indicate whether the parameter is valid. It is required to attach the DataContractAttribute attribute. The SysOperationContractProcessingAttribute attribute is optional. Attach the SysOperationContractProcessingAttribute attribute to use a custom UI builder with the contract class. Otherwise, the framework UI builder will be used to render the UI for dealing with the parameters when the report is run. To report a validation error, use the error method and write to the infolog. The error messages in the infolog will be marshaled from the service to the client and then rendered. Do not throw an error.
To add validation to an RDP data contract
- In the Microsoft Dynamics AX Development Workspace, open the AOT. Right-click the Classes node and then click New Class.
- Double-click the new class to open the classDeclaration in Code Editor.
- An RDP data contract must implement the SysOperationValidatable interface. The naming convention is [ReportName]Contract. The following code example illustrates the classDeclaration of the AssetDueReplacementContract data contract class that is used for the asset due replacement report.
/// <summary> /// The <c>AssetDueReplacementContract</c> class is used as the data contract for the <c>AssetDueReplacement</c> SSRS report. /// </summary> [ DataContractAttribute, SysOperationContractProcessingAttribute(classStr(AssetDueReplacementUIBuilder)) ] public class AssetDueReplacementContract implements SysOperationValidatable { CurrentOperationsTax postingLayer; AssetReplacementDate dateFrom; AssetReplacementDate dateTo; Name dimension; NoYes includeSubTotal; }
- In the AOT, right-click the new class you created, point to New, and then click Method.
- In the Code Editor, provide validation logic for the parameters. The following example illustrates the validation logic for the AssetDueReplacementContract data contract class parameters.
/// Determines whether the parameters are valid. /// </summary> /// <returns> /// true when the parameters are valid; otherwise, false. /// </returns> public boolean validate() { boolean isValid = true; if (!dateFrom) { isValid = checkFailed(strFmt("@SYS84753", "@SYS180311")); } if (!dateTo) { isValid = checkFailed(strFmt("@SYS84753", "@SYS180217")); } if (dateFrom > dateTo) { isValid = checkFailed(strFmt("@SYS300457", date2StrUsr(dateFrom, DateFlags::FormatAll), date2StrUsr(dateTo, DateFlags::FormatAll))); } return isValid; }