We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

server side message showing

GaddamV
Tera Contributor

Hi Team, I wrote a display BR script with two messages: first a warning message and then an info message. When I run this BR, the info message shows first and the warning message appears second. Why is this happening? Is there any reference order? I am sharing the code and screenshot. i need the warning should fisrt and info should be second

Advance thanks team

GaddamV_0-1782910512781.png

CODE 


(function executeRule(current, previous /*null when async*/ ) {

    var str = current.getValue('u_ai_agent');
   // gs.log('AI Agent reply' + str);
    var data = {
        problem: '',
        major_incidents: []
    };

    if (str) {

        // Get Problem Number
        var problemMatch = str.match(/problem:([^,]+)/);
        if (problemMatch) {
            data.problem = problemMatch[1].trim();
        }

        // Get Major Incident Numbers
        var majorMatch = str.match(/major_incident:(.*)/);
        if (majorMatch) {
            var majorValues = majorMatch[1].split(',');

            for (var i = 0; i < majorValues.length; i++) {
                if (majorValues[i].trim()) {
                    data.major_incidents.push(majorValues[i].trim());
                }
            }
        }
    }
  //  gs.log('JSON AI agent reply' + data);
  //  var messageParts = [];


    // Major Incident Message
    var majorLinks = [];

    if (data.major_incidents.length > 0) {

        for (var j = 0; j < data.major_incidents.length; j++) {

            var inc = new GlideRecord('incident');
            inc.addQuery('number', data.major_incidents[j]);
            inc.query();

            if (inc.next()) {
                majorLinks.push(
                    '<a href="/incident.do?sys_id=' +
                    inc.getUniqueValue() +
                    '" target="_blank">' +
                    inc.getValue('number') +
                    '</a>'
                );
               // gs.log('incident link message' + majorLinks);
            }
        }

        if (majorLinks.length == 1) {
            gs.addWarningMessage('AI Agent found the Major Incident: ' + majorLinks[0] + ' Click "Add Major Incident" to link this Incident.');
        } else if (majorLinks.length > 1) {
            gs.addWarningMessage('AI Agent found the Major Incidents: ' + majorLinks.join(', ') + ' Click "Add Major Incident" to link this Incident.');
        }
    }

    // Related Problem Message
    if (data.problem) {

        var prb = new GlideRecord('problem');
        prb.addQuery('number', data.problem);
        prb.query();

        if (prb.next()) {
            var problemLink = '<a href="/problem.do?sys_id=' +
                prb.getUniqueValue() +
                '" target="_blank">' +
                prb.getValue('number') +
                '</a>';

            gs.addInfoMessage('AI Agent found related Problem: ' + problemLink + ' Click "Add Problem" to link this Incident.');
           // gs.log('problem link message' + messageParts);
        }
    }


})(current, previous);
1 REPLY 1

joshuajacks
Kilo Sage

As I understand it, that's an oob order. From top to bottom Error, Info, Warning, Low, Moderate, High, regardless of how they show up in the script. I did a few tests in my pdi and that seems to be the case. You could use addErrorMessage to make it show up on top of the info message. Or use a different type for the info message if coloring is not as important as positioning.