Run script update to cmdb table ?

sukran
Mega Sage

In catalog task , we have a field name called " Server name " and  if this field name and cmdb table name is same ( comparison ), then have to update the variables in the same 

 

example : Field in Task 

find_real_file.png

Form CMDB record

find_real_file.png

 

If both are same , then need to update the variables values in to cmdb table record( Variables - which is available in the same catalog task )

 

Variables in task 

find_real_file.png

 

Both are reference field in the cmdb table ( location and configuration country ) , how to do this

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you need to write after update BR on sc_task with condition as below:

BR: current.request_item.cat_item == 'catalogItemSysId' && current.u_server_name != ''

Script below:

Note: Ensure you use valid catalog item sys_id; server name field; proper variable for device location

var gr = new GlideRecord('cmdb_ci');

gr.addQuery('name', current.u_server_name);

gr.query();

if(gr.next()){

gr.location = current.request_item.variables.device_location;

gr.update();

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

9 REPLIES 9

Muralidharan BS
Mega Sage
Mega Sage

Hi Sukran,

 

If you have a workflow for the catalog item, then add a activity called run script and include the below script.

 

var record = new GlideRecord('cmdb_ci'); 
record.addQuery('name', current.variables.server_name); //name of the variable in catalog item 
record.query(); 
if (record.next()) { 
 //record.setWorkFlow(false); // add this step if needed to stop cascading business rules
 record.location = current.variables.variable_name; // name of the variable where you update location
 record.update();
 }
 

 

Kindly mark my response helpful and correct, if this resolved your query.

Server name is a field in catalog task , not variables ... need to get value from the field 

Hi Sukran,

 

Ok, you can try a After business rule to update the cmdb_ci table.

To query the cmdb_ci with the server name from catalog task. Try to write the business rule on sc_task table. 

var record = new GlideRecord('cmdb_ci');
record.addQuery('name', current.server_name); //name of the field in catalog item
record.query();

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you need to write after update BR on sc_task with condition as below:

BR: current.request_item.cat_item == 'catalogItemSysId' && current.u_server_name != ''

Script below:

Note: Ensure you use valid catalog item sys_id; server name field; proper variable for device location

var gr = new GlideRecord('cmdb_ci');

gr.addQuery('name', current.u_server_name);

gr.query();

if(gr.next()){

gr.location = current.request_item.variables.device_location;

gr.update();

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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