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

Hi Simon,

you need to get the task for this RITM in the run script and then create record into your custom table based on the values

I could see you are using the values from RITM since you are having current object

Please explain are you updating the custom field u_affected_contact and the cmdb_ci field on RITM once task is closed?

Regards
Ankur

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

yes, you have to run the query in order to check if you are updating for the particular requested item only

Simon88
Kilo Contributor

Am I still doing something wrong? my hardware inventory table still written the cmdb_ci (which is 'service tag' field) as (empty).

 

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

var upd_inv= new GlideRecord("u_hardware_inventory");
upd_inv.addQuery('u_service_tag', current.cmdb_ci);
upd_inv.query();
var createInv = true;
while(upd_inv.next())
{
   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();
   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();
}

u_service_tag is a reference field? If yes, then try as below

gr.u_service_tag = current.cmdb_ci;

Or try 

gr.u_service_tag = current.configuration_item;

On the RITM level Configuration Item field name is configuation_item, not cmdb_ci so please make sure you are using the right name throughout the script. 

Also, place a log gs.info("SIMON - "+ current.configuration_item); to check if the value is coming from the RITM table.

All other values are inserting as expected? 

 

Regards,
Muhammad

updated the above comment!

Regards,
Muhammad