Monday, 13 March 2017

Adding Validation to RDP Data Contracts - AX 2012

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

  1. In the Microsoft Dynamics AX Development Workspace, open the AOT. Right-click the Classes node and then click New Class.
  2. Double-click the new class to open the classDeclaration in Code Editor.
  3. 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;
    }
    
    
  4. In the AOT, right-click the new class you created, point to New, and then click Method.
  5. 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;
    }

Monday, 6 March 2017

Debugger Windows In AX 2012

The following table describes the windows that make up the Microsoft Dynamics AX debugger:
Topic
Description
Explains how to use the Variables window.
Explains how to use the Watch window.
Explains how to use the Output window.
Explains how to use the Call Stack window.
Explains how to use the Breakpoints window.
These windows display detailed information about the current state of the executing code while you are debugging. You can move, undock, resize, or hide these windows. The chosen window layout persists between sessions. It is also possible to print or copy text from any window.
NoteNote
To restore the debugger UI to the default window layout, press CTRL+ALT+D or click View > Restore Default Layout.

The Variables and Watch windows each have a Name column that can be sorted. The default sorting order for each column is ascending, and the sort uses the complete text of the column to determine the order. The current sort direction is denoted by a small arrow inside the Name column. Clicking the column header reverses the current sort direction.
Sorting works separately for each window, including views that are grouped together. For example, in the Watch window, you can sort the Watch 1 view separately from the Watch 3 view. The current sorting does not persist across debugger instances. When the debugger is in break mode, the sorting state of each window is maintained. If you close the debugger, all sorting reverts to the default sorting the next time that the debugger is opened.

Deleting entries from the Watch window does not affect the current sort. When a new watch is added, it is added in ascending order regardless of the current sort order. The Name column has been re-sorted before the new watch appears in the correct position in the list.

Wednesday, 1 March 2017

Get Current User and User Name in AX

Static Name getCurUsername()
{
    return XUserInfo::find(false, curUserId()).name;
}

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...