- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 09:07 AM
Hello Experts!
I have a requirement to call a Flow from business rule. Now, online I'm getting 2 versions of syntax to do so:
2. My next question is: how does the flow receive the inputs that I'm passing from the business rule?
I need the inputs so that I can use these in the custom actions that I will be calling in my flow.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 09:38 AM - edited 02-17-2025 09:38 AM
Hi @Servicenow Use4,
Based on the documentation for .executeFlow():
Note: This API is replaced by ScriptableFlowRunner, which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner() method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.
Based on the above, the preferred method is the getRunner() method.
To pass in the inputs, you can refer to the doc (or below)
(function() {
try {
var inputs = {};
inputs['sys_id'] = '57af7aec73d423002728660c4cf6a71c'; // Pass the record's sys_id in as input.
var result = sn_fd.FlowAPI.getRunner() // Create a ScriptableFlowRunner builder object.
.action('global.markapproved') // Run the global scope action named markapproved.
.inForeground()
.inDomain('TOP/ACME') // Run the action from the TOP/ACME domain.
.withInputs(inputs)
.run(); // Run the action and return a FlowRunnerResult object.
var contextId = result.getContextId(); // Retrieve the context ID from the result
var dateRun = result.getDate();
var domainUsed = result.getDomainId(); // Retrieve the Domain ID from the result.
var flowName = result.getFlowObjectName();
var flowObjectType = result.getFlowObjectType();
var outputs = result.getOutputs(); // Retrieve any outputs from the action execution.
var newApprovalStatus = outputs['approval']; // Echo back the approval status for verification.
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();
For the 3rd question, you'll have to define a trigger as part of the flow. You can always select "Run Once" with a date in the past. Another option might be to use a subflow (instead of a flow). You can call the subflow via script and in that case of the subflow, there is no trigger.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 09:38 AM - edited 02-17-2025 09:38 AM
Hi @Servicenow Use4,
Based on the documentation for .executeFlow():
Note: This API is replaced by ScriptableFlowRunner, which deprecates the existing methods used to build objects and execute Workflow Studio flows and actions. Use the getRunner() method in the FlowAPI class to return a ScriptableFlowRunner object and use the associated methods. Use the ScriptableFlowRunner methods if you need to support domain separation.
Based on the above, the preferred method is the getRunner() method.
To pass in the inputs, you can refer to the doc (or below)
(function() {
try {
var inputs = {};
inputs['sys_id'] = '57af7aec73d423002728660c4cf6a71c'; // Pass the record's sys_id in as input.
var result = sn_fd.FlowAPI.getRunner() // Create a ScriptableFlowRunner builder object.
.action('global.markapproved') // Run the global scope action named markapproved.
.inForeground()
.inDomain('TOP/ACME') // Run the action from the TOP/ACME domain.
.withInputs(inputs)
.run(); // Run the action and return a FlowRunnerResult object.
var contextId = result.getContextId(); // Retrieve the context ID from the result
var dateRun = result.getDate();
var domainUsed = result.getDomainId(); // Retrieve the Domain ID from the result.
var flowName = result.getFlowObjectName();
var flowObjectType = result.getFlowObjectType();
var outputs = result.getOutputs(); // Retrieve any outputs from the action execution.
var newApprovalStatus = outputs['approval']; // Echo back the approval status for verification.
} catch (ex) {
var message = ex.getMessage();
gs.error(message);
}
})();
For the 3rd question, you'll have to define a trigger as part of the flow. You can always select "Run Once" with a date in the past. Another option might be to use a subflow (instead of a flow). You can call the subflow via script and in that case of the subflow, there is no trigger.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2025 09:37 PM
Thanks! using a subflow instead of a flow worked.
P.S, Apologies for the delayed response 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 10:00 AM
@Servicenow Use4 you can copy the code snippet from the flow designer and paste it in the BR and pass the required parameter. See the help from the SN Community
Run Flow from The Business Rules
If my response helped you kindly mark it as helpful.
Thank you,
Mahesh.