
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 12:10 AM
Hi,
Is it possible to display a JSON format payload in a popup once a UI Action is clicked?
I need to display a payload including: ticket number, opened_by, email, company and other information from the incident form.
Once I click on the 'Grant Access' i need to display the JSON payload in a popup. Any idea on how to do that?
Thanks,
Raphael
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 12:31 AM
So if you select 1 incident you should see details for that incident
If they select more than 1 you need to show json with data for all the selected incidents
Sample Script Below: you can enhance script include function as per your need to add the proper field values in the json and additional keys
UI Action: It should be client side;
Onclick - showPayload()
Script:
function showPayload(){
var sysIds = g_list.getChecked().toString();
var ga = new GlideAjax('getDetails');
ga.addParam('sysparm_name', 'getPayload');
ga.addParam('sysparm_sysIds', sysIds);
ga.getXML(processResponse);
function processResponse(response) {
var result = response.responseXML.documentElement.getAttribute("answer");
alert(result);
}
}
Script Include: It should be client callable
var getDetails = Class.create();
getDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getPayload: function(){
var sysIdStr = this.getParameter('sysparm_sysIds');
var sysIds = sysIdStr.toString().split(',');
var arr = [];
for(var i=0;i<sysIds.length;i++){
var gr = new GlideRecord('incident');
gr.get(sysIds[i]);
var obj = {};
obj['number'] = gr.number.toString();
obj['assignmentGroup'] = gr.assignment_group.getDisplayValue();
obj['openedBy'] = gr.opened_by.getDisplayValue();
obj['company'] = gr.company.getDisplayValue();
arr.push(obj);
}
return JSON.stringify(arr);
},
type: 'getDetails'
});
Output:
UI Action:
Script Include:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 12:15 AM
Hi,
it should be possible
Can you provide details on what is the UI action type ? List choice
Regards
ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 12:18 AM
Hi Ankur,
Yes it's a list choice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 12:31 AM
So if you select 1 incident you should see details for that incident
If they select more than 1 you need to show json with data for all the selected incidents
Sample Script Below: you can enhance script include function as per your need to add the proper field values in the json and additional keys
UI Action: It should be client side;
Onclick - showPayload()
Script:
function showPayload(){
var sysIds = g_list.getChecked().toString();
var ga = new GlideAjax('getDetails');
ga.addParam('sysparm_name', 'getPayload');
ga.addParam('sysparm_sysIds', sysIds);
ga.getXML(processResponse);
function processResponse(response) {
var result = response.responseXML.documentElement.getAttribute("answer");
alert(result);
}
}
Script Include: It should be client callable
var getDetails = Class.create();
getDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getPayload: function(){
var sysIdStr = this.getParameter('sysparm_sysIds');
var sysIds = sysIdStr.toString().split(',');
var arr = [];
for(var i=0;i<sysIds.length;i++){
var gr = new GlideRecord('incident');
gr.get(sysIds[i]);
var obj = {};
obj['number'] = gr.number.toString();
obj['assignmentGroup'] = gr.assignment_group.getDisplayValue();
obj['openedBy'] = gr.opened_by.getDisplayValue();
obj['company'] = gr.company.getDisplayValue();
arr.push(obj);
}
return JSON.stringify(arr);
},
type: 'getDetails'
});
Output:
UI Action:
Script Include:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2020 01:47 AM
Hi Ankur,
Thanks for this, I'll try this out. For my requirement, we only allow 1 record to be selected, If the user selects two it should alert the user that he/she should only select 1 record.