web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Get only the selected Lines from the InfoLog Using X++ for Reporting Needs.

(0) ShareShare
ReportReport
Posted on by 353

Hi

I need some assistance with reading info log messages at will starting at a certain line. If I want to read only line 2 and 3 from the info log and store them somewhere else like a table or a variable ? Can I do this for reporting purposes ? 

Take a look at the screen shot of the errors in my info log that I need to work with.

2867.errors.jpg

My question is I have to write a code which will read this infolog messages and only store the messages which are errors and not warnings. Or in other words if possible my code should only read the messages which starts with string letters (Document Number:) and the line after it (The Line for Worker).

Note* The order of these messages will always be the same. I mean the first line of the error will always be starting from (Document Number: ...) and the second line which follows will always start from (The Line For worker). So if you think about it the error consists of TWO lines at all times. I need to write a code which reads these two lines and can store them in a variable so that I can use this information in my Report for camparison with the Actual Data.

Code I have written so far returns the whole infolog all the messages from it. I need to build on from here please ?

 select * from BatchJobHistory 
     order by BatchJobHistory.StartDateTime Desc
       where BatchJobHistory.Caption == "generate Earnings Statement From Assignments" ;

      
    data = BatchJobHistory::showLog(BatchJobHistory.RecId);
    countItems = conlen(data);
    

    for(i=1;i<=countItems;i+=3)
    {
        infolog.import(conpeek(data, i+2));
        sysInfologEnumerator = SysInfologEnumerator::newData(infolog.copy(1,infologLine()));
        line = infologline();
    }
    
   
    while (sysInfologEnumerator.moveNext())  
   {  
     infoMessageStruct = new SysInfologMessageStruct(sysInfologEnumerator.currentMessage() + "\n");  
        }  


Any help will be greatly appreciated. Please question me if my question is poorly asked. Thank You

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at
    RE: Get only the selected Lines from the InfoLog Using X++ for Reporting Needs.

    Hi Muhammad_Ali,

    sysInfologEnumerator  has currentException() method that returns you Exception enum and you can check if it is Exception::Error or Exception::Warning. Then using sysInfologEnumerator .currentMessage() show message, so you don't need infolog.import(conpeek(data, i+2));

    And doing it in a loop you can count line number and do something if it is 2 or 3

  • Muhammad_Ali Profile Picture
    353 on at
    RE: Get only the selected Lines from the InfoLog Using X++ for Reporting Needs.

    Hi ievgen

       Thank you for your time.

      I understand your point but is it possible for you give me a code sample of what you are saying compared to my code that I have posted? Ievgen that will help me alot please if you think its possible.

    Thank you for your reply

  • Muhammad_Ali Profile Picture
    353 on at
    RE: Get only the selected Lines from the InfoLog Using X++ for Reporting Needs.

    Im currently on a very limited time frame to complete this requirement at my job. I need the help of the experience developers on this forum.

    Thank You so much

  • Suggested answer
    udaY-ch Profile Picture
    5,106 on at
    RE: Get only the selected Lines from the InfoLog Using X++ for Reporting Needs.

    Hi,

    try the below code,

    InfologData             infoLogData;
        SysInfologEnumerator    sysInfologEnumerator;
       
        info(strFmt("Info"));
        error(strFmt("error"));
        warning(strFmt("Warning")); 
      
        sysInfologEnumerator = SysInfologEnumerator::newData(infolog.infologData());
     
        while (sysInfologEnumerator.moveNext() )
        {
            switch (sysInfologEnumerator.currentException())
            {
               
                case Exception::Warning:
                     info(strFmt("Message is %1", sysInfologEnumerator.currentMessage()));
                break;
            }
        }

  • Muhammad_Ali Profile Picture
    353 on at
    RE: Get only the selected Lines from the InfoLog Using X++ for Reporting Needs.

    hi Udhaya -

      I understand your logic but I'm facing an issue with this code when I try to use my actual infolog with your code. Please take a look.

       select * from BatchJobHistory

        order by BatchJobHistory.StartDateTime Desc

          where BatchJobHistory.Caption == "generate Earnings Statement From Assignments" ;

       data = BatchJobHistory::showLog(BatchJobHistory.RecId);

       sysInfologEnumerator =  SysInfologEnumerator::newData(data);

     // I'm inserting actual data from my info log  into the SysInfologEnumerator::newData(data)  that I'm getting from  the batchjob history table

       while (sysInfologEnumerator.moveNext() )

        {

            switch (sysInfologEnumerator.currentException())

            {

                case Exception::Error:

                   doc = sysInfologEnumerator.currentMessage();

                break;

            }

        }

    I get an Error when the code reaches the case Exception::Error Line. Can you understand why It is not catching the error from my infolog ?

    5340.errors.jpg

    And here is my infolog - code should catch line 2 in error exception but it is not

    5340.errors.jpg

    Thanks

  • Verified answer
    Muhammad_Ali Profile Picture
    353 on at
    RE: Get only the selected Lines from the InfoLog Using X++ for Reporting Needs.

    This Piece of code did it for me. Thank You guys for suggesting me answers and directing me to the right path.

    while select * from BatchJobHistory

        order by BatchJobHistory.StartDateTime Desc

          where BatchJobHistory.Caption == "Generate Earning Statement From Assignments"

       {

           data = BatchJobHistory::showLog(BatchJobHistory.RecId);

           for(i=1; i<=conLen(data); i++)

           {

                if (typeof(conPeek(data,i)) == Types::Container)

                {

                   sysInfologEnumerator =  SysInfologEnumerator::newData(conPeek(data,i));

                   while (sysInfologEnumerator.moveNext())

                   {

                       switch (sysInfologEnumerator.currentException())

                        {

                            case Exception::Error:

                               infoMessageStruct = new SysInfologMessageStruct(sysInfologEnumerator.currentMessage());

                               exception = sysInfologEnumerator.currentException();

                               ErrorMessage = sysInfologEnumerator.currentMessage();

                               ErrorLineDocument = strScan(ErrorMessage,"Document Number:",0,strLen(ErrorMessage));

                               ErrorLineWorker = strScan(ErrorMessage,"The line for worker",0,strLen(ErrorMessage));

                               info(strFmt("%1; %2",

                                   exception,

                                   infoMessageStruct.message()));

                                   ErrorMessage = sysInfologEnumerator.currentMessage();

                               break;

                       }

    This Job breaks down the infolog into its containers and read the data from them and prints it on the screen.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans