- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 04:33 PM
Hi ServiceNow Gurus!
I have a catalog client script that runs "On Change". This script gets the value from "Field A" in the CMDB table and is displayed on the "Field AA" in the Service Catalog form.
What I want to achieve is to populate multiple fields in the Service Catalog form. For example, "Field B" in the CMDB table will display on the "Field BB" in the Service Catalog form, "Field C" to "Field CC" and so on.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CIDetails');
ga.addParam('sysparm_name','cidetails');
ga.addParam('sysparam_id',newValue);
ga.getXML(Process);
}
function Process(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('Field AA',answer);
}
Thank you very much.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 05:11 PM
Hello Carlo
Please try this:
CS:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var name = g_form.getValue('name');
var ga = new GlideAjax('CIDetails');//name of script include
ga.addParam('sysparm_name', 'cidetails');//name of function on script include
ga.addParam('sysparm_id', name);//name of field on form triggering call
ga.getXML(CIDetailsLookup);
}
function CIDetailsLookup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var answers = answer.split(',');
alert(answers);
g_form.setValue('fieldAA',answers[0]);
g_form.setValue('fieldBB',answers[1]);
g_form.setValue('fieldCC',answers[2]);
g_form.setValue('fieldDD',answers[3]);
}
SI:
var CIDetails = Class.create();
CIDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
cidetails: function(){
var retVal; // Return value
var cireq = this.getParameter('sysparm_id');
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('sys_id',cireq);
gr.query();
if(gr.next())
{
retVal = gr.fieldA+','+gr.fieldB+','+gr.fieldC+','+gr.fieldD;
}
return retVal;
},
type: 'CIDetails'
});
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
‎12-12-2017 04:53 PM
Script include for the above is:
var CIDetails = Class.create();
CIDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
cidetails: function() {
var gr=new GlideRecord("u_cmdb_ci"); //Pass the table name here
gr.addQuery("sys_id",this.getParameter('sysparam_id'));
gr.query();
gr.next();
if(gr.FieldA!=''){
return gr.FieldA;
}
},
type: 'CIDetails'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2017 05:11 PM
Hello Carlo
Please try this:
CS:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var name = g_form.getValue('name');
var ga = new GlideAjax('CIDetails');//name of script include
ga.addParam('sysparm_name', 'cidetails');//name of function on script include
ga.addParam('sysparm_id', name);//name of field on form triggering call
ga.getXML(CIDetailsLookup);
}
function CIDetailsLookup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var answers = answer.split(',');
alert(answers);
g_form.setValue('fieldAA',answers[0]);
g_form.setValue('fieldBB',answers[1]);
g_form.setValue('fieldCC',answers[2]);
g_form.setValue('fieldDD',answers[3]);
}
SI:
var CIDetails = Class.create();
CIDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
cidetails: function(){
var retVal; // Return value
var cireq = this.getParameter('sysparm_id');
var gr = new GlideRecord('cmdb_ci');
gr.addQuery('sys_id',cireq);
gr.query();
if(gr.next())
{
retVal = gr.fieldA+','+gr.fieldB+','+gr.fieldC+','+gr.fieldD;
}
return retVal;
},
type: 'CIDetails'
});
Please mark my response as correct and helpful if it helped solved your question.
-Thanks