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-26-2022 09:42 PM
Hi,
I hope the variable test2 has the correct CI name
updated script
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 = inc1.getUniqueValue(); //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', inc1.getUniqueValue()); // is this correct?? can i get the above CI in this incident record??
inc.update();
}
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:47 PM
Hi Ankur,
Yes test2 has the exact CI name, but in the above updated script we have queried in cmdb table current.cmdb_ci = inc1.getUniqueValue()
But how are we populating it in the incident table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 09:49 PM
ok thankyou, will try it Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2022 10:18 PM
Thank you for marking my response as helpful.
If my response helped you please mark it correct to close the question so that it benefits future readers as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader