Need to fix the below script

Pooja Khatri
Tera Contributor

Hi All ,

 

I have written the below part of a code in a function in a business rule , my requirement is when all the conditions written inside the function are true only then the function should be executed else it should be skipped 

 

The code written in the function is to skip on the notification part which means :: In case all condition true then we should send notification or else we should not send notification

 

The below part of function is not working in my existing Business rule

 

How can I fix this logic in the below code : 

 

function NC() {
    if (current.source_table == '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)  {
            return false;
 
        } else {
            return true;
        }
}
else
 {
        return false;
    }
1 REPLY 1

Peter Bodelier
Giga Sage

Hi @Pooja Khatri,

 

I'm not completely sure I understand your use case, but try it like this:

 

function NC() {
    if (current.source_table == 'change_request') {
        var changeSysId = current.document_id;
        var assignedto = current.approver.sys_id.toString();
        var CR = new GlideRecord('change_request');
        CR.addEncodedQuery("type=Normal^sys_id=" + changeSysId + "^assigned_to=" + assignedto + "^ORrequested_by=" + assignedto);
        CR.setLimit(1);
        CR.query();
        if (CR.hasNext()) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.