Passing Array to Script Include from client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2019 03:33 PM
Hi,
I am passing sys_id of selected records in list collector to script include. but Script Include is not able process input passed from client script.
#Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var list = g_form.getValue('list_collector');
var elements = list.split(',');
alert(elements);
var ga = new GlideAjax('SCCatalogHelper'); // Script include : FPSCHelperClient
ga.addParam('sysparm_name', 'getHostServersList'); // Function to be called in Script Include : GetUserInfo
ga.addParam('sysparm_cmdbciSysId', elements); // set UserId parameter
ga.getXML(updateFields);
}
function updateFields(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
#Script Include:
getHostServersList: function()
{
var result = [];
var array = this.getParameter('sysparm_cmdbciSysId').toString().split(",");
return array;
},
I have attached output from screen.
Appreciate your help.
Thank You
Kiran Patil

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2019 04:42 PM
Hi Kiran,
It should be return array.join(',');
Can you provide some additional details on what you are trying to accomplish?
-Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2019 05:28 PM
Try this
getHostServersList: function()
{
var result = [];
var array = this.getParameter('sysparm_cmdbciSysId').toString();
return array.join();
},
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2019 08:59 PM
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var list = g_form.getValue('list_collector'); //list will be a comma separated string
//var elements = list.split(',');
//alert(elements);
var ga = new GlideAjax('SCCatalogHelper'); // Script include : FPSCHelperClient
ga.addParam('sysparm_name', 'getHostServersList'); // Function to be called in Script Include : GetUserInfo
//ga.addParam('sysparm_cmdbciSysId', elements); // set UserId parameter
ga.addParam('sysparm_cmdbciSysId', list); //Pass the comma separated string
ga.getXML(updateFields);
}
function updateFields(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
Script Include
getHostServersList: function()
{
var result = [];
var array = this.getParameter('sysparm_cmdbciSysId').toString().split(",");
gs.log('--->this is what the script include received from client script: \n'+
array); //Use log to test the results;very helpful always to see what is going on
return array;
},
To view the log
System Log > All
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2019 09:10 PM
Hi Kiran,
What is your exact requirement here?
you are sending the array to script include from client script
var list = g_form.getValue('list_collector');
var elements = list.split(','); // split method returns an array
In script include again you are converting to array using toString() and again converting it to array using split().
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader