Sunday 10 October 2021

How to get last exception error message using x++ code

private InfologText getInfoLogMessage(int _infologPosition, Exception _logLevel, boolean _resetInfoLog)  

{

       #define.NewLine('\n')

    SysInfologEnumerator        enumerator = SysInfologEnumerator::newData(infolog.copy(max(_infologPosition,1), Global::infologLine()));

       SysInfologMessageStruct      msgStruct;

       Exception                           exception;

       InfologText                 infotext;

    while(enumerator.moveNext())

    {

           msgStruct = SysInfologMessageStruct::construct(enumerator.currentMessage());

           exception = enumerator.currentException();

 

           if(_logLevel == Exception::Info || _logLevel == exception

        || (_logLevel == Exception::Warning && exception == Exception::Error))

           {

                  if(infotext)

                  {

                         infotext += #NewLine;

                  }

               

                  infotext += strFmt('%1', msgStruct.message());

           }

    }

    if(_resetInfoLog)

    {

           infolog.clear(_infologPosition);

    }

}