- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2022 05:35 AM
Hi All,
I am having a requirement on catalog task form. On the form there is two editable field hostname and serial number. Serial Number auto populates when hostname is filled but if the hostname is of a new asset which is not present in pc_hardware table then the user needs to manually enter the serial number.
In manual case, we need to validate if the serial number is already present in pc_hardware table or not. If yes, we need to show the error msg with the name of asset to which the serial number is assigned and prevent saving the form.
As I am new and learning, kindly help me with the script to validate serial number and display error message.
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 05:28 AM
Can you try below scripts :
Yup! You can update scripts as below
Client script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('global.CMDBClientUtils'); //update script include name as needed
ga.addParam('sysparm_name', 'checkForSerialNumber');
ga.addParam('sysparm_serialnumber', g_form.getValue("serial_number"));
ga.addParam('sysparm_hostname', g_form.getValue('host_name')); //check the backend value of hostname variable
ga.getXML(checkSerialNumber);
}
function checkSerialNumber(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != 'no') {
g_form.clearValue('serial_number');
g_form.addErrorMessage(answer);
}
}
Script Include
var CMDBClientUtils = Class.create();
CMDBClientUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkForSerialNumber: function () {
try {
var answer;
var serialNumber = this.getParameter('sysparm_serialnumber');
var hostName = this.getParameter('sysparm_hostname');
var grHardware = new GlideRecord('cmdb_ci_pc_hardware');
grHardware.addQuery('serial_number', serialNumber);
grHardware.addQuery('name', '!=', hostName);
grHardware.query();
if (grHardware.next()) {
answer = 'Serial Number already exists, found in asset: ' + grHardware.getValue('name');
}
else {
answer = 'no';
}
return answer;
} catch (ex) {
gs.error(ex);
}
},
type: 'CMDBClientUtils'
});
If the above is not working, just share the screenshot of your form which shows the hostname field and serial number field.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 02:58 AM
Can you try below scripts :
Yup! You can update scripts as below
Client script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('global.CMDBClientUtils'); //update script include name as needed
ga.addParam('sysparm_name', 'checkForSerialNumber');
ga.addParam('sysparm_serialnumber', g_form.getValue("serial_number"));
ga.addParam('sysparm_hostname', g_form.getValue('host_name')); //check the backend value of hostname variable
ga.getXML(checkSerialNumber);
}
function checkSerialNumber(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != 'no') {
g_form.clearValue('serial_number');
g_form.addErrorMessage(answer);
}
}
Script Include
var CMDBClientUtils = Class.create();
CMDBClientUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkForSerialNumber: function () {
try {
var answer;
var serialNumber = this.getParameter('sysparm_serialnumber');
var hostName = this.getParameter('sysparm_hostname');
var grHardware = new GlideRecord('cmdb_ci_pc_hardware');
grHardware.addQuery('serial_number', serialNumber);
grHardware.addQuery('name', '!=', hostName);
grHardware.query();
if (grHardware.next()) {
answer = 'Serial Number already exists, found in asset: ' + grHardware.getValue('name');
}
else {
answer = 'no';
}
return answer;
} catch (ex) {
gs.error(ex);
}
},
type: 'CMDBClientUtils'
});
If the above is not working, just share the screenshot of your form which shows the hostname field and serial number field.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 03:16 AM
In the case of manually filling serial number and hostname does not match, it is not clearing out the value and saving the form after showing error msg.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 03:19 AM
can you share screenshot of the form where those two fields are present.
Or else drop me a mail at sumanthdosapati3@gmail.com so that i can connect and see.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 03:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2022 01:12 AM
Hi