How to trigger flow in record producer

mickydash2001
Tera Contributor

Hi All, Can anyone suggest how to trigger flow for a particular record producer? and can we create multiple tasks and approvals for record producers too like service catalogs? 

3 REPLIES 3

Community Alums
Not applicable

Amit Gujarathi
Giga Sage
Giga Sage

Hi @mickydash2001 ,
I trust you are doing great.

To trigger a flow for a particular record producer, you can use the "before record producer" business rule. This business rule is executed when a user submits a record producer, before the record producer is created. You can use this business rule to start a flow that performs additional processing before the record producer is created.

Here's some sample code that demonstrates how to trigger a flow for a specific record producer using the "before record producer" business rule:

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

    // Check if the record producer being submitted is the one we're interested in
    if (current.producer.name == "My Record Producer") {

        // Create a GlideRecord object for the Flow Definition table
        var flowDef = new GlideRecord("sys_flow_definition");

        // Set the query to find the flow definition we want to trigger
        flowDef.addQuery("name", "My Flow Definition");

        // Execute the query
        flowDef.query();

        // If a matching flow definition was found, trigger it
        if (flowDef.next()) {
            var flowAPI = new FlowAPI();
            flowAPI.startFlow(flowDef.getValue("sys_id"), current, null);
        }
    }

})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Hi @Amit Gujarathi

Thanks for the response.

Just one doubt. The tasks and approvals of flow are based on values selected in record producer. And here this business rule is triggering the flow before record producer. So will it work?