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

Thanks Ankur

You are welcome.

Regards
ankur

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

Hi Ankur, 

Shouldn`t this be done on the workflow/flow before creating the sc_task record as this use case looks specific to the catalog item and sc_task table is used by other catalog items too ?

Please correct me if I am wrong.

Thanks,
Rahul

Hi Rahul,

As per the question I assumed the field "u_server_name" will be updated by some Agent working on the catalog task; If that is the case then the workflow on RITM won't help. Hence after update BR on that table. This can also be handled using workflow run script once task is completed.

yes this can be achieved using Flow Designer with trigger as Field Updated.

If the server name is being populated during Catalog Task Creation itself; then the code to update the cmdb_ci record can be placed inside the Advanced Script section of Catalog Task Activity

Regards
Ankur

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

Thanks Ankur!