how do I get an array from the API in the script include and call it to the catalog client script

Topan Kamil
Tera Contributor

hello everyone, I am just learning ServiceNow, here I am trying to integrate Jira with ServiceNow using the API, but I have a problem in the script include here I am confused (do not understand) how to make the script include can make data from the array that comes from the API into a sting so that it can be called in the catalog client script, please help to explain whether my script call is wrong because the portal has read the data, but the results are still not correct, what should appear in the customer column is only the name, for example, topan. kamil.

 

thank you for your help, all your explanations will be very helpful for me and I will be very happy and hopefully if there are people who find the same case as me, they can be helped by this question.

1 ACCEPTED SOLUTION

@Topan Kamil 

sample script will be like this

function onLoad() {
	// var arruj=[];
	var ga = new GlideAjax('getUserJira');
	ga.addParam('sysparm_name', "GetUserJiraUppk");
	ga.getXML(HelloWorldParse);

	function HelloWorldParse(response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		var parsedData = JSON.parse(answer);

		var nameArr = [];

		for(var i=0;i<parsedData.length;i++)
			nameArr.push(parsedData[i].name.toString());

		g_form.clearOptions('customer');

		for(var j in nameArr)		
			g_form.addOption('customer', nameArr[j], nameArr[j]);

	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

11 REPLIES 11

@Topan Kamil 

so from that json which values you want to add to drop down?

you will have to parse the json accordingly

AnkurBawiskar_0-1674190799806.png

 

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

@Ankur Bawiskar I want the value of displayName in the JSON to be added to the drop-down.

@Topan Kamil 

are you saying you want these 2 names and want to add to drop down?

name -> kamil and topan.kamil

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

@Ankur Bawiskar Yes, is that possible, can you give an example?

@Topan Kamil 

sample script will be like this

function onLoad() {
	// var arruj=[];
	var ga = new GlideAjax('getUserJira');
	ga.addParam('sysparm_name', "GetUserJiraUppk");
	ga.getXML(HelloWorldParse);

	function HelloWorldParse(response) {
		var answer = response.responseXML.documentElement.getAttribute("answer");
		var parsedData = JSON.parse(answer);

		var nameArr = [];

		for(var i=0;i<parsedData.length;i++)
			nameArr.push(parsedData[i].name.toString());

		g_form.clearOptions('customer');

		for(var j in nameArr)		
			g_form.addOption('customer', nameArr[j], nameArr[j]);

	}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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