Display the array values from client script to the log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 01:23 PM
Hi,
I have the below Script include that pulls the onboarding applications that were given access when an employee is onboarding.
var GetApps = Class.create();
GetApps.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApplications:function(){
var ritm = '';
var applications = [];
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('sc_item_option.item_option_new.name','u_employee_id');
gr.addQuery('sc_item_option.value','E160799');
gr.query();
while (gr.next()) {
if(gr.request_item.cat_item.sys_id == '6e3b38b4137fa70035f0bc122244b0c5')
{
ritm = gr.request_item.number;
}
}
var rr = new GlideRecord('sc_item_option_mtom');
rr.addQuery('request_item.number', ritm);
rr.query();
while(rr.next()){
if((rr.sc_item_option.value == 'true') && (rr.sc_item_option.item_option_new.name != 'u_applications_list'))
{
applications.push(rr.sc_item_option.item_option_new.name.toString());
}
}
return JSON.stringify(applications);
},
type: 'GetApps'
});
Then I want all the applications checked during the onboarding to come on the form of Offboarding when the Offboarding Service Catalog form is being filled.
The script includes when ran in Background scripts, got the applications list feeded into an array called "applications"
Now my problem is with the client script to get the array values printed as info message. The client script is as below
var ga = new GlideAjax("GetApps");
ga.addParam("sysparm_name", "getApplications");
ga.getXML(getApplicationDetails);
}
function getApplicationDetails(response){
g_form.addInfoMessage('Hello World');
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != '')
{
var myObj = JSON.parse(answer);
}
}
I am not sure how I can get the values on the info message.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 01:43 PM
You can use tog_form.addInfoMessage print the application names
var ga = new GlideAjax("GetApps");
ga.addParam("sysparm_name", "getApplications");
ga.getXML(getApplicationDetails);
}
function getApplicationDetails(response){
g_form.addInfoMessage('Hello World');
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != '')
{
var myObj = JSON.parse(answer);
g_form.addInfoMessage('The application list is '+myObj.toString());
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 05:30 AM
Sajiv,
I tried it but couldn't get what I am expecting.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2019 01:43 PM
As you are passing only single value to an array, you don't need to do JSON stringify and parse
Try the below scripts
var ga = new GlideAjax("GetApps");
ga.addParam("sysparm_name", "getApplications");
ga.getXML(getApplicationDetails);
}
function getApplicationDetails(response){
g_form.addInfoMessage('Hello World');
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != '')
{
g_form.addInfoMessage(answer);
}
}
Script Include
var GetApps = Class.create();
GetApps.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getApplications:function(){
var ritm = '';
var applications = [];
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('sc_item_option.item_option_new.name','u_employee_id');
gr.addQuery('sc_item_option.value','E160799');
gr.query();
while (gr.next()) {
if(gr.request_item.cat_item.sys_id == '6e3b38b4137fa70035f0bc122244b0c5')
{
ritm = gr.request_item.number;
}
}
var rr = new GlideRecord('sc_item_option_mtom');
rr.addQuery('request_item.number', ritm);
rr.query();
while(rr.next()){
if((rr.sc_item_option.value == 'true') && (rr.sc_item_option.item_option_new.name != 'u_applications_list'))
{
applications.push(rr.sc_item_option.item_option_new.name.toString());
}
}
return applications.toString();
},
type: 'GetApps'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2019 05:33 AM
I do have mutiple values. That is the reason I used an array. The answer looks like below. When I ran the above script include in the Scripts - Background, the result I got is
docusign, onbase
I wanted the above values to be shown when Onboarding form is being filled.
I am using g_form.addInfoMessage to see if I am getting the values. But I am not getting them.