Script to copy variable answer from a RITM to the parent REQ

nmcl
Giga Expert

We have created a field for 'u_disable_opening_notification' on the REQ form and have also created this same field as a variable on RITMs.

This is a yes/no answer and needs to be transferred from the RITM variable to the parent request.


We have created a BR that tries to do this but it is not working. I am guessing that we need to create a glide record that matches the parent REQ to the RITM and then sets the field.


We have so far tried...


current.u_disable_opening_notification = current.variables.u_disable_opening_notification;


Any ideas?

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think you would want to run an after insert business rule on the request item table that copies this value up to the request. If you were to run this on the request, the item may not exist yet.



(function() {


  //get the gliderecord for the parent request


  var req = new GlideRecord('sc_request');


  if (req.get(current.request)) {


          req.u_disable_opening_notification = current.variables.u_disable_opening_notification;


          req.update();


  }


})();


View solution in original post

4 REPLIES 4

jagmjavier
Kilo Expert

you are using current for the req and current for ritm. If BR is set in req table you have to look for the related ritm though gliderecord and then to look forto do something like that:


current.u_disable_opening_notification = grRITM.variables.u_disable_opening_notification;




If BR is in ritm table you have to look for the related request though gliderecord function and to do:


grREQ.u_disable_opening_notification = current.variables.u_disable_opening_notification;




Both of them are ok. Everything will depend of your requirements.




Also you can take a look to the following post: Catalog Item variable not being assigned to Requests




Regards


Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think you would want to run an after insert business rule on the request item table that copies this value up to the request. If you were to run this on the request, the item may not exist yet.



(function() {


  //get the gliderecord for the parent request


  var req = new GlideRecord('sc_request');


  if (req.get(current.request)) {


          req.u_disable_opening_notification = current.variables.u_disable_opening_notification;


          req.update();


  }


})();


Hi Brad, I've tried this but get the below error.



JavaScript parse error at line (5) column (36) problem = missing ; before statement



Also, just to check - I want to use this field to determine whether to send a notification or not, will adding this as a 'after BR' will this be too late and the notification have already sent?



Thanks,


Nat


I have got round the javascript error (extra space on end of code copied) , but it's still not updating the field on the parent request?



Current code...


br.png


Is there any issue with the fields being different types between ESS and the REQ table?


I've set the values of each to be the same, so wouldn't have thought it would cause an issue?



Request Table


req_field.png



Variable


var_field.png