- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2022 08:18 AM
Hi I am having a requirement. I am having one catalog item to order virtual machines. It contains two variables : 'hostname' and 'serial number'. These two variables are not visible in form. They are visible on RITM and sc_task.
When the task is created for SD team then they fill this hostname variable. When they are filling the variable then the serial number should get auto-populated for that hostname.
Table from which virtual machines are :
cmdb_ci_pc_hardware
Fields on table : name > contains hostname of asset
serial_number > contains serial number of asset.
Can you help me achieving this. Thank you in advance!!!
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 12:59 AM
Hi, Thank you for the responses.
My issue is resolved. It is working fine for me now. Posting the script that I have written.
Script Include :
var Populate_serial_number = Class.create();
Populate_serial_number.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getID: function() {
var asset = this.getParameter('sysparm_host');
if(asset != ''){
var gr = new GlideRecord('cmdb_ci_pc_hardware');
gr.addQuery('name',asset);
gr.query();
if(gr.next()){
return gr.serial_number;
}
}
type: 'Populate_serial_number'
}
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// var host = g_form.getValue('hostname');
var number = g_form.getValue('serial_number');
var ga = new GlideAjax('Populate_serial_number');
ga.addParam('sysparm_name', 'getID');
ga.addParam('sysparm_host', newValue);
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('serial_number', answer);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2022 11:32 AM
You can use an onChange Client script that only runs on the request item and catalog task. My variables may not match yours put this code worked in my PDI.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.getReference('host_name', callback); //host_name is my variable and is a reference field.
}
function callback(host){
g_form.setValue('serial_number', host.serial_number); //first serial_numer is my variable and it is of type single line text
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2022 11:31 PM
Hi
My hostname field is single line text and the table from which we are getting value is different. This is not working for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2022 11:56 PM
Hi,
share the script you started with and where are you stuck?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2022 12:59 AM
Hi, Thank you for the responses.
My issue is resolved. It is working fine for me now. Posting the script that I have written.
Script Include :
var Populate_serial_number = Class.create();
Populate_serial_number.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getID: function() {
var asset = this.getParameter('sysparm_host');
if(asset != ''){
var gr = new GlideRecord('cmdb_ci_pc_hardware');
gr.addQuery('name',asset);
gr.query();
if(gr.next()){
return gr.serial_number;
}
}
type: 'Populate_serial_number'
}
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// var host = g_form.getValue('hostname');
var number = g_form.getValue('serial_number');
var ga = new GlideAjax('Populate_serial_number');
ga.addParam('sysparm_name', 'getID');
ga.addParam('sysparm_host', newValue);
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('serial_number', answer);
}