Interview Questions

Monday, May 12, 2014

TO Get last Info log event in ax 2009

static void LastInfoLog(Args _args)
{
    int i;
    str messageBody;
    ;
    try
    {
       info("In the 'try' block. (j1)");
       info("infolog!");
       throw warning("test warning");
       throw error("test error");
       info("infolog!");
       throw warning("test warning");
        //throw Exception::Error;
    }
    catch
    {
        for (i=1; i<=infolog.line(); i++)
        {
            messageBody = ":" + infolog.text(i);
        }
    }
    info(messageBody);
}

static void TOGetLasteventlog(Args _args)
{
    SysInfologEnumerator enumerator;
    SysInfologEnumerator enumeratorlocal;
    SysInfologMessageStruct msgStruct;
    Exception exception;
    int i,j;
    str  text,Textlocal,textmsg;
    int line = infolog.line();
;
    try
    {
       info("In the 'try' block. (j1)");
       info("infolog!");
       throw error("test error");
       throw warning("test warning");
       info("infolog!");
       throw warning("test warning");
        //throw Exception::Error;
    }
    catch (Exception::Error)
    {
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
            //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
        }
        info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));
    }
    catch (Exception::Info)
    {
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
            //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
        }
        info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));
    }
    catch (Exception::Warning)
    {
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
            //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
        }
        info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));
    }
    catch (Exception::Warning)
    {
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
            //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
        }
        info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));
    }
    infolog.clear(line);
   /* enumerator = SysInfologEnumerator::newData(infolog.cut());
    while (enumerator.moveNext())
    {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            text =strfmt('%1',exception);
            Textlocal = strfmt('%1',msgStruct.preFixTextElement(1));
            textmsg   = strfmt('%1',msgStruct.message());
          //  info(strFmt("Type: %1; Prefix: %2; Message: %3",exception,msgStruct.preFixTextElement(1),  msgStruct.message()));
    }
     info(strFmt("Type: %1; Prefix: %2; Message: %3",text,Textlocal,  textmsg));*/
}
In ax  2012:-
str errorMessage;
  
try
{
    throw error('Some error message being thrown here');
}
catch
{
    errorMessage = infolog.text(infologLine());
}
  
print errorMessage;
  
pause;

No comments:

Post a Comment