Change Task business rule - referencing parent Change Request fields

MacSWW
Giga Contributor

Hi all,

 

I've replicated the 'Change Events' Business Rule on the Change Task table to fire events for Change Task calendar notifications, however I can't get it to fire an event when the 'Approval' status changes. The rule runs perfectly for fields that are on the change_task table, but the 'Approval' field is taken from the parent Change Request (see attached jpg). The script I've got so far is below:

 

if (current.expected_start.changes() || current.due_date.changes() || current.assigned_to.changes() || current.change_request.approval.changesTo('requested') || current.change_request.approval.changesTo('approved')) {   
   if (!current.expected_start.nil() && !current.due_date.nil() && !current.assigned_to.nil()) {
       gs.eventQueue("u.change.task.calendar.notify", current, current.assigned_to, previous.assigned_to);
   }

 

The conditions I need help with are obviously the current.change_request.approval.changesTo('requested') || current.change_request.approval.changesTo('approved')). I'd basically like to fire an event if the parent Change Request approval status changes to 'requested' or 'approved' so it would update the calendar entry in the 'assign to' persons diary. I have tried a couple of variations on the above, but is it as simple as just trying to dot-walk to the 'Approval' field?

 

Hopefully I'm just missing something obvious, but any help would be really appreciated!

 

Thanks,

Mac

1 ACCEPTED SOLUTION

MacSWW
Giga Contributor

Thanks for your help both - adding to the existing Change Events BR did work, but I had trouble passing the 'Assigned To' value from the Change Task through the gs.eventQueue, so the wrong person was getting the notification (the Assigned To person on the Change Request was getting it instead).



For reference, I ended up creating a new rule on the change_request table similar to this post:


Help with creating an event to trigger emails on a different table



Name: Change Task icalendar update


Table: change_request


When: before


Update


Condition: current.approval.changesTo('approved')


Script:


var ct = new GlideRecord("change_task");


ct.addQuery("change_request", current.sys_id); //find tasks under the current change request


ct.addQuery("assigned_to", "!=", ""); //make sure the assigned to field isn't blank


ct.addQuery("state", "<=", 2); //look for only open or work in progress tasks


ct.query(); //run the query


while (ct.next()) { //continue until all change tasks are found


    gs.eventQueue("u.change.task.calendar.notify", ct, gs.getUserID(), gs.getUserName()); //trigger event


}



Thanks for all the help and pointing me in the right direction



Mac


View solution in original post

6 REPLIES 6

MacSWW
Giga Contributor

Thanks for your help both - adding to the existing Change Events BR did work, but I had trouble passing the 'Assigned To' value from the Change Task through the gs.eventQueue, so the wrong person was getting the notification (the Assigned To person on the Change Request was getting it instead).



For reference, I ended up creating a new rule on the change_request table similar to this post:


Help with creating an event to trigger emails on a different table



Name: Change Task icalendar update


Table: change_request


When: before


Update


Condition: current.approval.changesTo('approved')


Script:


var ct = new GlideRecord("change_task");


ct.addQuery("change_request", current.sys_id); //find tasks under the current change request


ct.addQuery("assigned_to", "!=", ""); //make sure the assigned to field isn't blank


ct.addQuery("state", "<=", 2); //look for only open or work in progress tasks


ct.query(); //run the query


while (ct.next()) { //continue until all change tasks are found


    gs.eventQueue("u.change.task.calendar.notify", ct, gs.getUserID(), gs.getUserName()); //trigger event


}



Thanks for all the help and pointing me in the right direction



Mac


Please mark the post answered, and replies helpful/correct if it helped.


-Anurag