The CreatorCon Call for Content is officially open! Get started here.

How to display JSON format payload in a pop up once a UI Action is clicked

Raphael Dizon
Mega Expert

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.

find_real_file.png

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

1 ACCEPTED SOLUTION

@Raphael Dizon 

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:

find_real_file.png

UI Action:

find_real_file.png

Script Include:

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

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

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

Thanks for the help, can I fix the payload's appearance like can I add a line break after each object?

Hi Raphael,

I don't think so since it is a json structure i.e. array of json objects

Regards
ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Niamul Arifin
Tera Expert

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?