when Request is cancelled Send notification to Requester, Assigned to & Approver

Arjun Reddy Yer
Tera Guru

Can anyone help me in getting the solution @priyasunku @Ankur Bawiskar @BharathChintala @Sumalatha Y @AnveshKumar M @Allen Andreas @asifnoor @Brad Tilton @Pradeep Sharma @Sonu Parab @Sandeep Dutta @Hemant Goldar @Mohit Kaushik 

 

when Request is Cancelled Send notification to Requester, Assigned to & Approver (if Request is required for Approval).

I had written Notification, Created Event & written Business Rule but it's not triggering notification.

 

Notification:

 

 

yerasumalli_1-1679974873179.png

yerasumalli_2-1679974924058.png

yerasumalli_3-1679974973844.png

Event:

 

yerasumalli_4-1679975149625.png

Business Rule:

 

yerasumalli_5-1679975526787.png

yerasumalli_6-1679975579288.png

 

2 ACCEPTED SOLUTIONS

Gopi Naik1
Kilo Sage

Hi @Arjun Reddy Yer ,

 

Remove recipients added in "Who will receive"  section and check "event param1 contains recipients" as true. And use below code in business rule.

 

(function executeRule(current, previous /*null when async*/) {
var arr=[];
arr.push(current.requested_for.toString());
arr.push(current.assigned_to.toString());
var approval=new GlideRecord('sysapproval_approver');
approval.addQuery('sysapproval',current.sys_id.toString());
approval.query();
while(approval.next()){
arr.push(approval.approver.toString());
}
gs.eventQueue('sc_req_item.canceled',current,arr.toString());

})(current, previous);

 

 

 

 

If my solutions helps you to resolve the issue, Please accept solution and Hit "Helpful".

Thanks,
Gopi

View solution in original post

Aman Kumar S
Kilo Patron

Hi @Arjun Reddy Yer ,

The issue is with your BR condition, you should keep it as "Stage changes to Closed complete OR stage changes to Request Canceled".

You are using "and" condition instead.

 

ALso the eventQueue function the params are very critical, for your case it  should be something like:

gs.eventQueue('sc_req_item.canceled',current, current.assigned_to,childAssignedTo.string());

 

And also mark event parm 1 contains recipients and 2 in the notification

 

Best Regards
Aman Kumar

View solution in original post

9 REPLIES 9

Aman Kumar S
Kilo Patron

Hi @Arjun Reddy Yer ,

The issue is with your BR condition, you should keep it as "Stage changes to Closed complete OR stage changes to Request Canceled".

You are using "and" condition instead.

 

ALso the eventQueue function the params are very critical, for your case it  should be something like:

gs.eventQueue('sc_req_item.canceled',current, current.assigned_to,childAssignedTo.string());

 

And also mark event parm 1 contains recipients and 2 in the notification

 

Best Regards
Aman Kumar

Is the below mentioned Business Rule Script is correct

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

// Add your code here
var childAssignedTo = [];
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request',current.sys_id); // or ritm.addQuery('request',current.sys_id);
ritm.query();
while(ritm.next()){
childAssignedTo.push(ritm.assigned_to);
}

gs.eventQueue('sc_req_item.canceled',current.assigned_to,childAssignedTo.toString());

})(current, previous);

As I have mentioned above, change your few lines of code as below:

 

while(ritm.next()){
childAssignedTo.push(ritm.getValue("assigned_to"));// use of getValue is critical here
}

gs.eventQueue('sc_req_item.canceled',current,current.assigned_to,childAssignedTo.toString());

 

Best Regards
Aman Kumar