- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 02:44 AM
Hello Team,
I'm creating new catalog item where i'm creating a variable's
- Application
- configuration item
- used for environment
Here I'm trying to populate values 'used for environment' variable, based on selection on configuration item, I have selected multiple values on configuration item list collector field which is reference to table cmdb_ci_server her I'm trying to auto populate 'used for environment' values from server table on 'used for environment' variable, but it's not populating multiple values it's showing only one value which i is first one other two are not populating. how to populate multiple values.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 03:16 AM
First create an onChange Catalog Client Script on the Configuration item variable. The script will look something like this, depending on your Script Include and variable names.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CILookup');//name of the Script Include
ga.addParam('sysparm_name', 'getCIDetails');//name of the function in the Script Include
ga.addParam('sysparm_cis', newValue);
ga.getXML(getCI);
function getCI(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('variableName', answer);//name of your text variable
}
}
Next create a Script Include with the same name used in the GlideAjax line above, ensuring the Client callable box is checked. Your script include will look like this
var CILookup = Class.create();
CILookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCIDetails: function() {
var ciArr =[];
var cis = this.getParameter('sysparm_cis');
var ci = new GlideRecord('cmdb_ci_server');
ci.addQuery('sys_id', 'IN', cis);
ci.query();
while(ci.next()){
ciArr.push(ci.used_for.toString());
//if you want the used_for values comma-separated use the line above
//or if you want the used_for values each on one line in the text field
//then use the line below
ciArr.push(ci.used_for.toString() + '\n');
}
return ciArr.join(',');
},
type: 'CILookup'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 02:48 AM
Hi,
Refer below link.
Mark it correct and helpful.
Thanks
Bhagyashri Sorte.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 02:51 AM
Hi,
here the solution to use, please try to create a new onchange client script:
If I have answered your question, please mark my response as correct and/or helpful.
Thank you very much
Cheers
Alberto

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 02:56 AM
Hello JRY,
Write an on change client script on Configuration item variable,
var gajax=new GlideAjax('abc')//name of script include
gajax.addParam('sysparm','xyz');//function name
gajax.addParam('sysparm_condig',newValue);//newValue contain sys_id of all selected ci;
gajax.getXML(pqr);
function pqr(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
answer.setValue('field name',answer);//field name of used for field.
}
----------------------------------------------------------------
Script include
function:xyz()
{
var arr=[];
var config_values=this.getParameter('sysparm_condig');
arr=config_values.split(',').toString();
var i;
var gr= new GlideRecord('server table name');
for(i=0;i<arr.length;i++)
{
gr.addQuery('ci',arr[i]);//put correct value name instead of CI. here for every ci we are geeting used for
gr.addQuery();
if(gr.next())
{
gr.getValue(used_for+'\n');
}
}
return arr.toString();
}
Please Mark it helpful/correct if my answer helps in any way to resolve your query.
Reach out to me if any more help required.
Regards
Yash.K.Agrawal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2020 03:16 AM
First create an onChange Catalog Client Script on the Configuration item variable. The script will look something like this, depending on your Script Include and variable names.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CILookup');//name of the Script Include
ga.addParam('sysparm_name', 'getCIDetails');//name of the function in the Script Include
ga.addParam('sysparm_cis', newValue);
ga.getXML(getCI);
function getCI(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('variableName', answer);//name of your text variable
}
}
Next create a Script Include with the same name used in the GlideAjax line above, ensuring the Client callable box is checked. Your script include will look like this
var CILookup = Class.create();
CILookup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCIDetails: function() {
var ciArr =[];
var cis = this.getParameter('sysparm_cis');
var ci = new GlideRecord('cmdb_ci_server');
ci.addQuery('sys_id', 'IN', cis);
ci.query();
while(ci.next()){
ciArr.push(ci.used_for.toString());
//if you want the used_for values comma-separated use the line above
//or if you want the used_for values each on one line in the text field
//then use the line below
ciArr.push(ci.used_for.toString() + '\n');
}
return ciArr.join(',');
},
type: 'CILookup'
});