Check the if application name exists
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-28-2024 05:33 PM
I was trying to check if the application already exists in cmdb_ci_appl table. If exist i was an alert message saying application already exist and which should work onchange of the variable. I have created a single line text field as new_asset_name and trying below code but i'm not getting any alert message even the application exist. Please help me with the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2024 11:27 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.