The Zurich release has arrived! Interested in new features and functionalities? Click here for more

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

ccajohnson
Kilo Sage

I am curious as to what you have built. You say you are using a variable, but your script and screen shots seem to indicate you have custom fields on the form. Please verify that this is the case.



One nice thing about variables within catalog items is that the variables are stored in a common place. So, if you change the variable in one task it shows up in the next. You just need to make sure that the variables are available when creating the task from the workflow. Please let us know your current design so that we can solution accordingly.


I created custom fields on the sc_task form. This is how we have done it in the past with success, but for some reason when I try to utilize a nearly identical script in this situation it is not working.



You are suggesting that I create the variables in the current.variables set and they will automatically update each other?


Yes, variables are unique in that they store them in a common pool. If you change a variable in the item, they are changed in the task. Likewise, if you change a variable in one task it will be changed in any sub-sequential tasks.



Something you may want to experiment with is using variables instead of custom fields. One other nice thing about variables is that they are associated with a particular catalog item. This way you do not have to create multiple custom fields on your forms and have multiple UI Policies running to show and hide them as necessary. When doing so, some things you may want to consider:



-     When creating the variables, use a higher order number so that they appear at the end.


-     If you do not want them to appear in approvals, un-check the Show on Summary checkbox.


-     My guess is that these are not being filled out in the form, so you will need to create a Catalog UI Policy to hide them on the form.


-     You can leverage the Create Catalog Task workflow activity to show and hide the variable in the task if it is not needed right away.



Hopefully that will give you a framework to use in the future.


mark_zieglmeier
Kilo Expert

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


One thing you may want to keep in mind is that as of Geneva, ServiceNow uses anonymous function calls and no longer uses the onBefore() onDisplay() or onAfter() functions. I have seen that the syntax of the functions that I used in Fuji, no longer work. Here is your code using the anonymous function syntax:


(function executeRule(current, previous /*null when async*/) {


//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;  


      }


})(current, previous);