- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 04:17 PM
Hi SN Gurus!
I have a Service Catalog Form that contains the CMDB Name and Owner Group fields. The CMDB Name references to the CMDB table. I want to auto-populate the Owner Group field based on the CMDB Name selected by the user.
Please help!
Carlo
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 04:50 PM
Here you go.
Create an OnChange catalog client script on CMDB name field with the script as below. Please make sure to update line no 16 i.e Pass the owner field variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CmdbDetails');
ga.addParam('sysparm_name','cmdbdetails');
ga.addParam('sysparam_id',newValue);
ga.getXML(Process);
}
function Process(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("PASS OWNER FIELD VARIABLE HERE",answer);
}
create a script include
Name : CmdbDetails
Client Callable : True
Script :
var CmdbDetails = Class.create();
CmdbDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
cmdbdetail: function() {
var gr=new GlideRecord("cmdb_ci"); //Pass the table name here
gr.addQuery("sys_id",this.getParameter('sysparam_id'));
gr.query();
gr.next();
if(gr.owner!=''){
return gr.owner;
}
},
type: 'CmdbDetails'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 04:27 PM
Hello Carlo,
As a best practice, you can do this via Client Script + GlideAjax approach. The wiki link mentioned here has a sample code.
http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
You can also refer the below thread for reference and adjust your code accordingly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 04:29 PM
This might help
Adding Dependent Variables - ServiceNow Wiki
Or you can create catalog client script to populate second value.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 04:43 PM
I was thinking of using a catalog client script to populate the Owner Group field but no idea how to start. Is there a sample code that I could use?
I am a novice in scripting and have a hard time completing tasks as simple as this!
Regards,
Carlo

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 04:50 PM
Here you go.
Create an OnChange catalog client script on CMDB name field with the script as below. Please make sure to update line no 16 i.e Pass the owner field variable.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('CmdbDetails');
ga.addParam('sysparm_name','cmdbdetails');
ga.addParam('sysparam_id',newValue);
ga.getXML(Process);
}
function Process(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("PASS OWNER FIELD VARIABLE HERE",answer);
}
create a script include
Name : CmdbDetails
Client Callable : True
Script :
var CmdbDetails = Class.create();
CmdbDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
cmdbdetail: function() {
var gr=new GlideRecord("cmdb_ci"); //Pass the table name here
gr.addQuery("sys_id",this.getParameter('sysparam_id'));
gr.query();
gr.next();
if(gr.owner!=''){
return gr.owner;
}
},
type: 'CmdbDetails'
});