The below script is triggering incorrect Events for notification .. how can I fix it ?

Pooja Khatri
Tera Contributor

Hi All, 

 

I have written a business rule which is triggering multiple events in the single script , for every of the email notifications for request , task it is triggering event : normal_change.approval.inserted ... in ideal scenario , for isRequest function it should trigger : request.approval.inserted event for isSCTask it should trigger event : sc_task.approval.inserted and so on , I am not pasting down the entire script , but there is some issue with the below part of the code which is everytime triggering : normal_change.approval.inserted for any of the function call .

 

How can I fix the below part ?

 

if (current.state.changes() && current.state == 'requested') {
    var event = "";
    if (isRequest)
        event = "request.approval.inserted";
    else if (isSCTask)
        event = "sc_task.approval.inserted";
    else if (isStdChange)
        event = "std_change_proposal.approval.inserted";
    else if(isEmergencychange)
        event = 'approval.inserted';
    else if (isnormalchange)
        event = "normal_change.approval.inserted";
    else if (!(current.source_table == 'change_request' || current.sysapproval.sys_class_name == 'change_request'))
        event = "approval.inserted";

    if (event != "") {
        gs.eventQueue(event, current, gs.getUserID(), gs.getUserName());
        updateTask(current, current.approver.getDisplayValue() + " requested to approve task");
    }
}
5 REPLIES 5

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
How the variable isnormalchange is getting calculated?


Thanks and Regards,

Saurabh Gupta

Hi @Saurabh Gupta   - isNormalChange is calling the function checkNormalChange and inside the function is the below script : 

 

function checkNormalchange() {
    if (current.source_table == 'change_request' || current.sysapproval.sys_class_name == '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 true;
}
 
Can you please help me to fix the below script and understand why it is exaclty not working

Hi,
To check if the approver triggered is on Normal change, you can use below script-

 

function checkNormalchange() {
    if ( current.sysapproval.sys_class_name == 'change_request' && current.sysapproval.type=='Normal')
            return true;
else
return false;
}

 





Thanks and Regards,

Saurabh Gupta

Hi @Saurabh Gupta  - approval do gets triggered on the normal change itself it is jus that for other functions like isRequest , isSCTask it is triggering event == normal_change.approval.inserted which in ideal scenario it should not and it should trigger specific events related to that functions which are there in the above script shared .

 

How can I fix that part ?