[AX2009 Code] Convert Infolog to string

  In need to recall today once more the code for this, I'm just creating an entry here; call this with the following: Infolog2Str(infolog.copy(1, infolog.line()), infolog.num())

static str Infolog2Str(container _c, int _len)
{
    int                 oldInfologLen;
    int                 i, start, end, len;
    container           c, currentEntry;
    int                 entryLen, entryType;
    str                 entryText;
    str                 s;
    ;

    s = '';
    c = _c;

    len = conlen(c);

    // Must have at least one element
    if(len == 0)
        return '';

    // first element is a container with one integer element (version)
    if(typeof(conpeek(c, 1)) != Types::Container ||
        conlen(conpeek(c, 1)) != 1 ||
        typeof(conpeek(conpeek(c, 1), 1)) != Types::Integer)
        return '';

    // Save the current number of entries
    oldInfologLen = _len;

    // append to the info log
    for(i = 2; i <= len; i++)
    {
        // each entry is a container
        if(typeof(conpeek(c, i)) != Types::Container)
            break;

        // Get the current entry
        currentEntry = conpeek(c, i);

        // Get the current entry length
        entryLen = conlen(currentEntry);

        // entries can be formatted in 2 ways
        // 1. [exceptionType, Text]
        // 2. [exceptionType, Text, helpUrl, actionClassId, action]
        if(entryLen != 2 && entryLen != 5)
            break;

        // Validate types
        if(typeof(conpeek(currentEntry, 1)) != Types::Integer ||
            typeof(conpeek(currentEntry, 2)) != Types::String)
            break;

        // Extract the first 2 values in the entry
        entryType = conpeek(currentEntry, 1);
        entryText = conpeek(currentEntry, 2);

        // Add the entry to the current infolog
        s += entryText;
    }

    return s;
}

No comments:

Post a Comment