- 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:52 PM
Please use below sample catalog client script
function onChange(control, oldValue, newValue, isLoading) {
var gn = g_form.getReference('source_ci'); // source_ci is variable for CI
if (gn) {
g_form.setValue("sourcesys_owner", gn.assigned_to);
g_form.setValue("sourcebus_owner",gn.owned_by);
//g_form.setValue("resolver_group",gn.support_group);
}
}
Regards,
Sachin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 04:54 PM
Hello Sachin,
FYI : g_form.getReference() methods are no longer recommended due to their performance impact. The top ways to get information from the server are g_scratchpad, and asynchronous GlideAjax lookup.
http://wiki.servicenow.com/index.php?title=Client_Script_Best_Practices#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2017 06:59 PM
Hi Pradeep,
Thank you so much for your help on this one.
In case additional CMDB fields will need to be used in the Service Catalog, how do I add the fields to the scripts?
Thank you.
Carlo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2018 01:05 PM
Hi Pradeep
Thanks for helping people with your recommended solutions. Really appreciate your efforts!
I have a similar requirement to get a value from a field on the CMDB table and to populate it on the catalog form field. But in my scenario, I need to populate Memory field value of an Assigned to user field from cmdb table so to match the Requested for field on the catalog form and to populate the memory field from cmdb table to RAM field on catalog form.
In summary, we want system to validate whether the "Requested For" has at least 16GB of RAM or not?
What I need to modify in your script?
Pls. advise.
Regards
Manu