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
(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);