Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Cancel Approval record and Restart Flow designer Flow

ShivangiC
Tera Contributor

 Please help me with Business rule in order to implement if Expense record is modified before Approval or Rejection, the existing record in Approval table must be set with State-> No longer Required and then my Flow Designer flow must restart. Currently this is my Business Rule script:-

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

    // 1. Cancel existing approvals
    var approvalGR = new GlideRecord('sysapproval_approver');
    approvalGR.addQuery('sysapproval', current.sys_id);
       
        while (approvalGR.next()) {
            approvalGR.state = 'not_required';
            approvalGR.update();
        }

        // 2. Restart Flow Designer flow
        if (current.flow_context) {
            try {
                sn_fd.FlowAPI.restartFlow(current.flow_context);
                gs.info('Flow restarted for record: ' + current.number);
            } catch (e) {
                gs.error('Error restarting flow: ' + e);
            }
        } else {
            gs.warn('No active flow context found for record: ' + current.number);
        }

})(current, previous);
 
This is an After Update BR with conditions:- when 'Updates' changes and 'Approval Status' is 'Requested'.
0 REPLIES 0