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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

it should be possible

Can you provide details on what is the UI action type ? List choice

Regards
ankur

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

Hi Ankur,

Yes it's a list choice

@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

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.