
- 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 01:53 AM
Hi,
In that case you can add this validation check
Updated Client Script
function showPayload(){
var sysIds = g_list.getChecked().toString();
var arr = sysIds.split(',');
if(arr.length > 1){
alert('You are allowed to select only 1 value');
return;
}
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);
}
}
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-14-2020 03:55 AM
Hi Ankur,
Thanks for the help, can I fix the payload's appearance like can I add a line break after each object?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 11:23 PM
Hi Raphael,
I don't think so since it is a json structure i.e. array of json objects
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
‎06-05-2024 12:21 PM
I am trying to do something similar based on what mentioned above.
However, instead of the alert message, I want have a Related Link which will open a glideDialogWindow and that window will have the payload of the selected 1 or many incidents.
@Ankur Bawiskar Can you help with this?