Dynamics Ax Get and Remove text from the Infolog

Sometimes you want a process to log infolog data into a text field instead of sending it to the infolog. For example you are posting 6 custom made journalTables and if something goes wrong you want the infologdata to be stored in a Log field on the table and you want to continue with the processing of the other journalTables.

Then you will have a catch statement where you will need to get the infolog data and store it into the field but there are some difficulties :

  • First you want only the data generated by your process and not the data that might have already been in the infolog.
  • Second you want to clear the errors from you code from the infolog without clearing all the rest of the infolog data.

The key is to work with the infolog.line() method to remember when to start keeping track of the lines in the infolog.

We can demonstrate this with the following job :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
static void LIB_KeSae_TestInfologRemoval(Args _args)
{
    int line;
    str omittedText;
    ;
 
    error("error1");
    error("error2");
 
    // Now we have 2 records in the infolog
    // From now on we want the following entries in the infolog to be stored
    // somewhere and omitted from the infolog window
 
    // Remember the number of entries before the custom code (in this case line = 2)
    line = infolog.line();
 
            //Customer code
            error("error3");
            error("error4");
            error("error5");
 
    // Here we want to retrieve statement 3, 4 and 5 en clear those from the infolog
    omittedText = global::LIBGetTextFromInfoLog(line + 1, true);
 
    // Some infolog entries after our code
    error("error6");
    error("error7");
}

The following code is the code from the GetTextFromInfolog method :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static str LIBGetTextFromInfoLog(int _startLine = 1, boolean _clearInfo = true)
{
    int currentLine;
    str retValue;
    ;
 
    /*
        Do not use infolog.infologData to get the infolog data because that creates a copy and clears the actual infolog.
        Then the infolog.line() method will return 0 afterwards and you cannot clear the selected lines anymore
    */
 
    for(currentLine = _startLine; currentLine < = infolog.line(); currentLine++)
    {
        retValue += 'n' + infolog.text(currentLine);
    }
 
    // _startLine -1 because the infolog method will add 1
    if(_clearInfo)
        infolog.clear(_startLine -1);
 
    return retValue;
}

The infolog.clear() method will now take the startline into account and only clear the infolog entries from our code and leave the other entries intact as shown in the result of this job :

Result of the infolog after removing entries
Result of the infolog after removing entries
Warning: count(): Parameter must be an array or an object that implements Countable in /customers/5/2/1/ksaelen.be/httpd.www/wordpresses/dynamicsaxblog/wp-includes/class-wp-comment-query.php on line 399

2 thoughts on “Dynamics Ax Get and Remove text from the Infolog

  1. Nicely written, thanks. I’ve referenced this but changed the output to return a container though, just so that multiple lines are seperated clearly for when I log them to a table.

  2. Yeah, indeed, then you are able to store them on seperate records. For now, I always use it in a status memo field

Leave a Comment Yourself

Your email address will not be published. Required fields are marked *