How can we query glide record in cmdb table and place that cmdb value in incident record? Please correct my script if wrong

Sandeep109
Mega Contributor

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

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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?

ok thankyou, will try it Ankur

@Sandeep 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader