How can we query glide record in cmdb table and place that cmdb value in incident record? Please correct my script if wrong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 09:37 PM
Hi,
Wanted to query glide record of cmdb table and place that cmdb value in incident record is the below script correct?
have written query for Glide Record for cmdb and incident table
var inc1=new GlideRecord("cmdb_ci");
inc1.addQuery('cmdb_ci.name',test2); //test2 is the CI name am quering for
if(inc1.next())
{
current.cmdb_ci=test2; //wanted to place this CI in the incident record for which i have written the GlideRecord below??
}
var inc = new GlideRecord('incident');
inc.addQuery('correlation_id', alertid);
inc.addEncodedQuery('stateIN6,7,8');
inc.query();
if (inc.next()) {
inc.setValue('state', 2);
inc.setValue('close_code', '');
inc.setValue('close_notes', '');
inc.setValue('cmdb_ci',test2); // is this correct?? can i get the above CI in this incident record??
inc.update();
Regards,
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 03:03 AM
Hi Ankur,
Could youplease help me in the below:
its working in background scripts but not working in the inbound actions code, i tried giving gs.info and check in the system log but in the logs just "it is CI" this coming and not the value of test2. And i have also checked in logs for test2 if its working and the CI number is populating correctly in the log. Please advice
var inc1=new GlideRecord("cmdb_ci");
inc1.addQuery('name'=test2);
inc.query();
while(inc1.next())
{
var cmdb= inc1.getUniqueValue();
}
gs.info("it is CI ",cmdb);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 03:42 AM
Hi,
I am not sure what's your complete script
but please declare the variable outside and assign value within if
var cmdb;
var inc1=new GlideRecord("cmdb_ci");
inc1.addQuery('name'=test2);
inc.query();
while(inc1.next())
{
cmdb= inc1.getUniqueValue();
}
gs.info("it is CI ",cmdb);
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
01-26-2022 09:56 PM
Is this a normal backend script you are running or you are doing it by Business Rule?