Due date on RITM is not updating from Business Rule

oanderson
Tera Contributor

I created a Business Rule on the sc_request table that should change the child RITM's due date to the REQ's due date on update:

(function executeRule(current, previous /*null when async*/) {
	// Add your code here
	var gr = new GlideRecord('sc_req_item');
	gr.get('request.sys_id', current.sys_id);
	gr.query();
	gr.due_date = current.due_date;
	gr.update();
})(current, previous);

oanderson_0-1699984416015.png

 

When I debug Business Rules and update the REQ's due date, I see that this Business Rule is the only one running. If I update the REQ's due date and go to the child RITM, the due date is still the original due date, not the new one. However, if I look at the RITM's history, it shows the last update as the BR setting the due date to the new one:

oanderson_1-1699984604951.png

oanderson_2-1699984642605.png

oanderson_3-1699984690593.png

Any idea why the RITM history shows the update occurring, but the due date value on the RITM form is not updating?

 

Thanks!

 

 

 

1 ACCEPTED SOLUTION

harshav
Tera Guru

Please update the code.

	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('request', current.sys_id);
	gr.query();
        while(gr.next()){
	   gr.due_date = current.due_date;
	   gr.update();
        }

View solution in original post

4 REPLIES 4

harshav
Tera Guru

Please update the code.

	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('request', current.sys_id);
	gr.query();
        while(gr.next()){
	   gr.due_date = current.due_date;
	   gr.update();
        }

This worked... but I'm not sure I understand why. If I'm successfully grabbing the RITM object using gr.get(), why does iterating through the query actually update the value on the RITM, but using gr.get() and updating gr does not?

This worked... but I'm not sure I understand why. If I'm successfully grabbing the RITM object using gr.get() and seemingly updating the due_date, why does iterating through the query() actually update the value, but using gr.get() does not?

In your case i believe you don't need 'request.sys_id', you can pass in 'request'. also by removing the query() line will work. for get method query is not required. Also typically it is used for single record, there is a good chance that there will be multiple records in this case so get is not recommended.