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

Anurag Tripathi
Mega Patron
Mega Patron

Hi,



Change this line


gs.eventQueue("u.change.task.calendar.notify", current, current.assigned_to, previous.assigned_to);




TO


var email_id = //valid email


gs.eventQueue("u.change.task.calendar.notify", current, email_id, email_id);






current.assigned_to gives the user object but this parameter in gs.eventQueue wants email id and not user object.


-Anurag

sumeet_n
Kilo Guru

Hi Mac,



Couple of checkpoints I would suggest:


1. Remove all the if conditions. Add them one by one and test them. This will make sure all of them are correct.


2. Give a thought to the fact that you are writing this server side code on change_task table, and you are trying to anticipate the change in approval field of change_request table. This is where I doubt.




I would not try to include the changes happening on change_request table in a BR on change_task table. Edit Change Events BR on change_request table to include (current.change_request.approval.changesTo('requested') || current.change_request.approval.changesTo('approved'))) these conditions to trigger the required event.


Sumeet,



The second point that you mentioned works just fine. I can confirm it. To Debug removing the If's can be tried.


-Anurag

MacSWW
Giga Contributor

That's a good point - I'll try adding an extra condition into the Change Events BR to fire the u.change.task.calendar.notify event when the approval changes.



Anurag and Sumeet - thanks for your help. I'll test and post back the results.



Mac