5/16/2018

How to get error message

The error messages in AX are stored in the global object infolog. So when trying to print the message, we need to access infolog instance and fetch the information. I created a static method in my utility class so I can reuse it whenever I want to do that in my code.
The method is,

public static str getErrorMsg(int _infologPosition = 0)
{
    str msg;
    int currentLine;
    ;
    for (currentLine = _infologPosition + 1; currentLine <= infologline(); currentLine++)
    {
        msg += infolog.text(currentLine) + '\n';
    }

    return msg;
}


So in code, when I want to capture the message, I can just,

try
{
......
}
catch
{
errorMsg = UtilityClass::getErrorMsg();
......
}

No comments:

Post a Comment