Prevent form submission if no approval using business rule

TanushaP
Kilo Contributor
I used before insert and update business rule  i.e when change request risk is high and state is authorize form should save when atleast one approval is got but without any approvals also form is saving can someone help
 
 
 
(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    if (current.risk == 'High'&& current.state==-3)
    {
        // Query the Approvers table (usually sysapproval_approver)
        var gr = new GlideRecord('sysapproval_approver');
        gr.addQuery('sysapproval', current.sys_id); // link to this Change Request
        gr.addQuery('state', 'approved'); // look for at least one Approved
        gr.query();

        if (!gr.hasNext()) {
            gs.addErrorMessage('High-risk changes require at least one approver in Approved state before submission.');
            current.setAbortAction(true); // block save
        }
    }


})(current, previous);
0 REPLIES 0