trigger flow from business rule

jean-pauldehaas
Tera Guru

Hi All,

 

i have a flow for decomissioning a pc, the flow should kick off if an update is done from AD on the computer table.

when the computer gets disabled in AD and this information gets updated in servicenow, the flow should kick of and created the requested item that is attached to the flow.

users are also able to manually create the request but when the request is created automatically the approval in the flow should be skipped.

im not sure how to start is there anyone who can hellp me on the way

1 ACCEPTED SOLUTION

@jean-pauldehaas 

I don't think you can pass any other input to flow

You can do this

1) create a hidden variable on your catalog item and set it via onLoad with some value and hide that variable always

2) then check that variable value in your flow

3) if it has value then it means it is submitted via manual request

4) when flow triggers via BR this variable will be empty

This will help you to skip approval

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@jean-pauldehaas 

you can use after update BR and check in the condition if it was manually triggered in an interactive session or not

Then trigger flow

Condition: Field Logic

Script:

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

    // Add your code here
    if (!gs.getSession().isInteractive()) {
        try {
            var inputs = {};
            inputs['current'] = ; // GlideRecord of table:
            inputs['table_name'] = 'incident';

            // Execute Synchronously: Run in foreground.
            // var timeout = ; //timeout in ms
            //sn_fd.FlowAPI.executeFlow('global.test_flow', inputs, timeout)
            sn_fd.FlowAPI.executeFlow('global.test_flow', inputs);
        } catch (ex) {
            var message = ex.getMessage();
            gs.info(message);
        }

    }

})(current, previous);

ScriptableFlowRunnerResult 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar thanks!

 

how do i implement in this script that it should skip te approval ? 

@jean-pauldehaas 

when triggered via script you can pass an input to flow via script and based on that input you will know if approval has to be skipped or not

To handle this you can use IF logic and check the value of input

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

apologies but i need some help on that one.

 

i have this now:

 

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

    // Add your code here
    if (!gs.getSession().isInteractive()) {
    try {
       
        var inputs = {};
        inputs['table_name'] = 'sc_req_item';
        inputs['request_item'] = current; // GlideRecord of table: sc_req_item

        // Start Asynchronously: Uncomment to run in background.
        // sn_fd.FlowAPI.getRunner().flow('global.pc_decommission').inBackground().withInputs(inputs).run();
               
        // Execute Synchronously: Run in foreground.
        sn_fd.FlowAPI.getRunner().flow('global.pc_decommission').inForeground().withInputs(inputs).run();
       
    } catch (ex) {
        var message = ex.getMessage();
        gs.error(message);
    }
    }
   
})(current, previous);