Need to fix the below script in Business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 08:36 AM
I want to implement the logic of when the approver is assigned to or requested by it should skip the logic in the below Business rule using an if condition ?
if(task == 'change_request'){
var changeSysId = current.document_id;
var assignedto = current.approver.sys_id.toString();
var CR = new GlideAggregate('change_request');
CR.addEncodedQuery("type=Normal^sys_id=" + changeSysId + "^requested_byORassigned_to=" + assignedto);
CR.query();
Can anyone please help me to complete this code ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 08:53 AM
@Pooja Khatri Here is the complete script.
if(task == 'change_request'){
var changeSysId = current.document_id;
var assignedto = current.approver.sys_id.toString();
var CR = new GlideAggregate('change_request');
CR.addEncodedQuery("type=Normal^sys_id=" + changeSysId + "^assigned_to=" + assignedto+"^ORrequested_by="+assignedto);
CR.addAggregate('COUNT');
CR.query();
var count = 0;
if(CR.next()){
count = CR.getAggregate('COUNT');
}
if(count>0){
//if count is greater than 0 which means approver user of change is either a requester or an assigned_to
current.setAbortAction(true);
}
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2023 10:25 PM
@Pooja Khatri Please mark the answer correct if it manages to address your issue.