How to copy field value back from catalog TASK to RITM?

Simon88
Kilo Contributor

Hi,

There's a mandatory field value I need to capture from catalog task ticket when close, after that I need that field value to store back into the parent RITM ticket (which is the current) in order to write that value into a table, how can I copy the value of this same field from TASK to RITM in the workflow?

I added this line into the 'Create Task' stage and obviously it didn't work, after the TASK ticket is closed, can still see this cmdb_ci field on the RITM field as blank and still mandatory.

Regards,

Simon.

1 ACCEPTED SOLUTION

Bhagyashri Sort
Kilo Guru

Hi, 

Please refer below thread, it might helpful to you.

https://community.servicenow.com/community?id=community_question&sys_id=a3eff2eddb58dbc01dcaf3231f96...

 

Mark it correct and helpful.

Thanks

Bhagyashri Sorte.

View solution in original post

16 REPLIES 16

MrMuhammad
Giga Sage

Hi Simon,

RITM and Catalog Task has one to many relationship, which means one RITM might have multiple tasks associated. So, which task field value needs to copy to RITM? 

if there is only one task then you can create a Run Script activity in workflow with the below code. 

Replace <FIELD_NAME> with actual field name of sc_Task & ritm.

var gr = new GlideRecord('sc_Task');
gr.addEncodedQuery("request_item", current.getValue("sys_id"));
gr.query();

if (gr.next()) {
  current.<FIELD_NAME> = gr.<FIELD_NAME>; // replace <FIELD_NAME> with actual field name on sc_Task & ritm.
  current.update();
}

Thanks,

Sharjeel

Regards,
Muhammad

mr18
Tera Guru
Tera Guru

Instead of from the workflow you can try it using before update business rule

Table: sc_task

Condition: State changes to close

Script:

var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", current.request_item);
gr.query();
if(gr.next()) {
gr.cmdb_ci = current.cmdb_ci;
gr.update();
}

Simon88
Kilo Contributor

I have a run script stage right after the TASK in the workflow, which is trying to write all info into a table including this cmdb_ci from the TASK ticket (only 1 TASK ticket). So does this mean I still need to run a query to pull back out the cmdb_ci value from the TASK?

var gr = new GlideRecord('u_hardware_inventory');
gr.initialize();
gr.u_service_tag = current.cmdb_ci.getDisplayValue();
gr.u_sys_user = current.u_affected_contact.getDisplayValue();
gr.u_emp_id = current.u_affected_contact.employee_number.getDisplayValue();
gr.u_location = current.u_affected_contact.location.getDisplayValue();
gr.u_emp_status = current.u_affected_contact.active.getDisplayValue();
gr.u_monitor = 2;
gr.insert();

If your workflow is on RITM table then Yes. As it doesn't know which task has been created in the previous activity. 

Regards,
Muhammad