Gs.addInfoMessage is not displayed

Jyotshna_M
ServiceNow Employee
ServiceNow Employee

I have UI action which makes a AJAX call to script include to reject the request, and on successful rejection info message is displayed  using the below snippet.

 

if (current.getValue("document_id"))
{
gs.info("display value "+ current.getDisplayValue("document_id"));
gs.addInfoMessage(gs.getMessage("Rejected approval for {0}", GlideStringUtil.escapeHTML(current.getDisplayValue("document_id"))));
}

This script it called for every record rejected, i.e if i bulk reject 10 records, the script is executed 10 times and log statement is getting printed but alert is not seen.

FYI : This is working fine if i just reject a single record , and failing for multi select
3 REPLIES 3

AshishKM
Kilo Patron
Kilo Patron

Hi @Jyotshna_M ,

The given code is not complete for analysis, please share the full code of UI Action and Script Include which is used for AJAX call.

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Community Alums
Not applicable

When you run a UI action on a single record, the inbound object to the script is different to when you run it with multi select.

 

You need to detect this difference and when multi select is used you need to iterate through each row and perform the action on each row separately.

 

For example:

var checkedList = g_list.getChecked();
for(var i=0; i<checkedList.length; i++){
// Do something with checkedList[i]
}

Jyotshna_M
ServiceNow Employee
ServiceNow Employee
Below are the code snippets for ui actions and also the script include.

function onClick() {
var selectedSysIds = g_list.getChecked();
g_modal.showFields({
title: getMessage("Enter comments for rejection"),
fields: [{
type: 'textarea',
name: 'comments',
label: getMessage('Comments'),
mandatory: true
}],
size: 'sm'
}).then(function(fieldValues) {
var comments = JSON.stringify(fieldValues.updatedFields[0].stagedValue);
var selectedSysIds = g_list.getChecked();
var ga = new GlideAjax('sn_shift_planning.ScheduleAjaxProcessor');

 

//method
ga.addParam('sysparm_name', 'rejectRequest');
//parameters
ga.addParam('sysIdList', selectedSysIds);
ga.addParam('sourceTable', 'sn_shift_planning_shift_swap_request');
ga.getXMLAnswer(getResponse);

 

function getResponse(answer) {
var result = JSON.parse(answer);
var approvalist = result.list;
for( var id in approvalist) {
//method for reject
var ga = new GlideAjax('sn_wfo.WFOApprovalUtilsAjax');
ga.addParam('sysparm_name', 'rejectApproval');
ga.addParam('sysparm_comment', comments);
ga.addParam('sysparm_approvalId', approvalist[id]);
ga.getXMLAnswer(gaCallBack);
}
function gaCallBack(answer) {
var result = JSON.parse(answer);
if (result.status) {
setTimeout(function() {
g_list.refresh();
}, 1000);
}}
}
});
}

WFOApprovalUtils changes the state to rejected and calls other script include

grApproval.setValue('state', 'rejected');
grApproval.update();
new global.ApprovalUserFeedback().rejected(grApproval);
result.status = 'success';

ApprovalUserFeedback :

rejected: function(current) {
gs.info("display value "+ current.getDisplayValue("document_id"));
if (gs.getProperty(this.property_name, "true") == "true")
if (current.getValue("document_id"))
{
gs.addInfoMessage(gs.getMessage("Rejected approval for {0}", GlideStringUtil.escapeHTML(current.getDisplayValue("document_id"))));
}
else
gs.addInfoMessage(gs.getMessage("Rejected approval for {0}", GlideStringUtil.escapeHTML(current.getDisplayValue("sysapproval"))));
}
}

Tried printing the text from getinfomessage and that is logged correctly