- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 08:36 AM
I have a catalog item which has a reference field "Virtual Machine" referencing to virtual machine table. The another variable is "Cloud Provider". Virtual machine table has a field "Resource Group"
I have another table "Cloud resource container" which has fields - name and cloud provider. The name in "Cloud resource container" table matches with the "Resource Group" in virtual machine table.
I want the "Cloud Provider" variable in catalog item to be populated with the field cloud provider in "Cloud Resource container" table. How to do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 09:29 AM
Hi @Shalika ,
Create onchange catalog client script, Fill mandatory details details and select proper catalog
Note : Replace proper table name and field variable names.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var gaPhone = new GlideAjax('getAjax');
gaPhone.addParam('sysparm_name', 'get_provider');
gaPhone.addParam('sysparm_vm', newValue);
gaPhone.getXML(_handleResponse);
function _handleResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('cloud_provider', answer); // Replace your Cloud Provider
}
}
Script Include :-
var getAjax = Class.create();
getAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
get_provider: function() {
var vm = this.getParameter('sysparm_vm');
var gr = new GlideRecord("VirtualMachineTableName");
gr.addQuery("sys_id", vm);
gr.query();
if (gr.next()) {
var grCloud = new GlideRecord("CloudResourceContainerTableName");
grCloud.addQuery("name", gr.resource_group);
grCloud.query();
if (grCloud.next()) {
return grCloud.cloud_provider;
}
}
},
type: 'getAjax'
});
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2022 09:29 AM
Hi @Shalika ,
Create onchange catalog client script, Fill mandatory details details and select proper catalog
Note : Replace proper table name and field variable names.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var gaPhone = new GlideAjax('getAjax');
gaPhone.addParam('sysparm_name', 'get_provider');
gaPhone.addParam('sysparm_vm', newValue);
gaPhone.getXML(_handleResponse);
function _handleResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('cloud_provider', answer); // Replace your Cloud Provider
}
}
Script Include :-
var getAjax = Class.create();
getAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
get_provider: function() {
var vm = this.getParameter('sysparm_vm');
var gr = new GlideRecord("VirtualMachineTableName");
gr.addQuery("sys_id", vm);
gr.query();
if (gr.next()) {
var grCloud = new GlideRecord("CloudResourceContainerTableName");
grCloud.addQuery("name", gr.resource_group);
grCloud.query();
if (grCloud.next()) {
return grCloud.cloud_provider;
}
}
},
type: 'getAjax'
});