How to check if application already exists in CMDB.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 04:09 AM
I was trying to check if the application already exists in cmdb_ci_appl table. So i have written below mentioned client script on change of New asset name variable which is single line text.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var vdr = new GlideRecord('cmdb_ci_appl');
vdr.addQuery('name',newValue);
vdr.query();
if(vdr.next())
{
alert('Application already exists.');
g_form.setValue('new_asset_name','');
}
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2024 11:09 PM
hi @SushmithaHemi ,
GlideRecord is not recommended on Client script.
GlideRecord is server side API if you want go get some data or validate from the server use GlideAjax API.
for example
Script include:
var getCILocal = Class.create();
getCILocal.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCIName: function() {
var cis = this.getParameter('sysparam_ci');
var vdr = new GlideRecord('cmdb_ci_appl');
vdr.addQuery('name', cis);
vdr.query();
if (vdr.hasNext()) {
return 'true'; // Return string 'true'
} else {
return 'false'; // Return string 'false'
}
},
type: 'getCILocal'
});
client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var att = new GlideAjax('getCILocal'); // Name of your Script Include
att.addParam('sysparm_name', 'getCIName');
att.addParam('sysparam_ci', newValue);
att.getXMLAnswer(function(answer) {
if (answer === 'true') {
alert('Application already exists.');
g_form.clearValue('assest_name'); // replace 'assest_name' with 'your_variable_name'
}
});
}
Please mark my solution as Accept, If you find it helpful.
Thanks,
BK