Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Pass Variables from one task to the next in RITM

mark_zieglmeier
Kilo Expert

I am working on a solution to pass variables from one task to the next as it passes down the workflow. This is because the later tasks need information provided by the earlier tasks. I have added the fields below to the bottom of tasks. (u_ip_address, u_printer_model)
find_real_file.png

Then I wrote the below business rule to copy u_ip_address from our Network task into any tasks that are created from the RITM. However this is not populating. I have some rules written in the exact same way for similar catalog items that all work. however this one will not fill in the IP field.

function onBefore(current, previous) {

//Populate IP Address from network task from Hardware Request

var pc = new GlideRecord('sc_task');

pc.addQuery('request_item.request', current.request_item.request);

pc.addQuery('assignment_group', '287ebd7da9fe198100f92cc8d1d2154e'); //network group

pc.addNotNullQuery('u_ip_address');

pc.query();

if(pc.next()){

current.u_ip_address = pc.u_ip_address;

}

}

Any Assistance would be greatly appreciated!

1 ACCEPTED SOLUTION

mark_zieglmeier
Kilo Expert

I ended up re-making the Business Rule with identical code and everything began working as expected.


View solution in original post

9 REPLIES 9

Madhu27
Tera Expert

Please use current.update() as follows


                            if(pc.next()){  


                                      current.u_ip_address = pc.u_ip_address;  


                                      current.update();


                            }



Thanks


PS: please hit like/helpful...if it helps


Still had the same issue. It came up blank in the new task.


Deepak Kumar5
Kilo Sage

Try with After insert BR.


  1. var pc = new GlideRecord('sc_task');  
  2. pc.addQuery('request_item', current.request_item);  

I changed the BR to be an after insert and it did not work. I would actually want this before insert, as I want the BR to search for the correct task and pull the data as it is inserting the new record.