Wait for Field Value change in Flow Designer

alexander_winkl
Tera Expert

Can flow designer detect a change in field value for the purposes of restarting the entire flow? We have a requirement that any time the Due Date value changes on our record, the flow should restart so that it can re-evaluate which state it should be in based on a script. I currently have the Flow designed to trigger any time a record is created or updated, and the Due Date changes and isn't empty. My fear is that the Flow will create a new instance of Flow each time the record is updated, without cancelling the old flow.

1 ACCEPTED SOLUTION

Jon23
Mega Sage

hi @alexander.winkley@accenturefederal 

One approach is to have your main flow to trigger 'Only if not currently running'.

Then have a before business rule to trigger when the 'Due Date' changes. The BR script will cancel the existing workflow(s).

Your main workflow will then trigger again as it is not currently running:

example:

before business rule calls a flow designer action on Due Date change (code grabbed from flow designer code snippet):

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

    try {
        var inputs = {};
        inputs['sourcerecord'] = current; // String 

        // Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
        var result = sn_fd.FlowAPI.getRunner().action('global.cancel_flow').inForeground().withInputs(inputs).run();
        var outputs = result.getOutputs();

        // Current action has no outputs defined.		
    } catch (ex) {
        var message = ex.getMessage();
        gs.error(message);
    }

})(current, previous);

Flow designer action looks up records on the sys_flow_context table that matches incident record:

find_real_file.png

For each record run the script to cancel:

find_real_file.png

View solution in original post

9 REPLIES 9

surajp
Mega Guru
Hi Alexander, Please give more detail on why do you expect to cancel the old flow instance or flow execution. It is expected that multiple executions can be created, but they will be processed one after other like schedule job. Check sys_trigger table. Regards, Suraj

Jon23
Mega Sage

hi @alexander.winkley@accenturefederal 

One approach is to have your main flow to trigger 'Only if not currently running'.

Then have a before business rule to trigger when the 'Due Date' changes. The BR script will cancel the existing workflow(s).

Your main workflow will then trigger again as it is not currently running:

example:

before business rule calls a flow designer action on Due Date change (code grabbed from flow designer code snippet):

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

    try {
        var inputs = {};
        inputs['sourcerecord'] = current; // String 

        // Start Asynchronously: Uncomment to run in background. Code snippet will not have access to outputs.
        var result = sn_fd.FlowAPI.getRunner().action('global.cancel_flow').inForeground().withInputs(inputs).run();
        var outputs = result.getOutputs();

        // Current action has no outputs defined.		
    } catch (ex) {
        var message = ex.getMessage();
        gs.error(message);
    }

})(current, previous);

Flow designer action looks up records on the sys_flow_context table that matches incident record:

find_real_file.png

For each record run the script to cancel:

find_real_file.png

Kim Sullivan
Tera Guru

Any other ideas on this?  I don't want to cancel my whole flow just to check if a field changed.

Hi @Kim Sullivan 

I would suggest posting a new question to the community with more details of your requirement. 

The original poster of this question specifically wanted their flow to restart on the field change.