We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

No SHarjeel. u_service_tag is just a 'String' field. And yes all other fields are inserted correctly, as you can see my screenshot.

Can you try below

var get_ci = new GlideRecord('sc_task');
get_ci.addEncodedQuery("request_item", current.getValue("sys_id"));
get_ci.query();
if (get_ci.next()) {
   current.configuration_item = get_ci.cmdb_ci;
   current.update();
}

var upd_inv= new GlideRecord("u_hardware_inventory");
upd_inv.addQuery('u_service_tag', current.configuration_item.getDisplayValue());
upd_inv.query();
var createInv = true;
while(upd_inv.next())
{ 
   gs.info("SIMON CI While - " + current.configuration_item.getDisplayValue());
   upd_inv.u_sys_user = current.u_affected_contact.getDisplayValue();
   upd_inv.u_emp_id = current.u_affected_contact.employee_number.getDisplayValue();
   upd_inv.u_location = current.u_affected_contact.location.getDisplayValue();
   upd_inv.u_emp_status = current.u_affected_contact.active.getDisplayValue();
   upd_inv.u_monitor = 2;
   upd_inv.update();
   createInv = false;
}

if (createInv)
{
   var gr = new GlideRecord('u_hardware_inventory');
   gr.initialize();
   gs.info("SIMON CI - " + current.configuration_item.getDisplayValue());
   gr.u_service_tag = current.configuration_item.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();
}

 

Let me know what you get in the logs. 

Regards,
Muhammad

Simon88
Kilo Contributor

It is the cmdb_ci variable not configuration_item, as you can see the screenshot from my TASK ticket that I have entered the value and also the RITM ticket after the TASK is closed, it is still not copying the RITM cmdb_ci value.

You are right. OOB its configuration_item. Anyhow, have you try placing the logs, and did you get the value there for cmdb_ci? 

Regards,
Muhammad

Hi Sharjeel, no luck, the gs.info showing empty value.