Retrieve subflow input values through script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2024 06:16 PM - edited 06-29-2024 06:16 PM
Hi,
I am trying to create a script that will return the input values from a subflow that has completed. I don't have a reason for this, I just am playing around and wanted to see if it could be done.
If anyone has any ideas, any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2024 10:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2024 10:23 PM
Hi @Yashsvi
Thank you for replying back, however I am not looking for how to do inline scripting in flow. I am looking to create a script for a business rule or scheduled job where I can retrieve the subflow inputs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2024 10:35 PM
Hi @Dazler,
To create a script for a business rule or a scheduled job that retrieves the input values of a subflow after it has completed-
Create a Script Include:
var SubflowUtils = Class.create();
SubflowUtils.prototype = {
initialize: function() {},
getSubflowInputs: function(flowContextId) {
var flowContext = new GlideRecord('sys_flow_context');
if (flowContext.get(flowContextId)) {
var inputs = flowContext.variables;
return inputs;
}
return null;
},
type: 'SubflowUtils'
};
Create a Business Rule:
- Create a new Business Rule on the appropriate table (e.g., sys_flow_context if you want to trigger when a subflow completes).
- Set the business rule to run after the subflow completes
(function executeRule(current, previous /*null when async*/) {
var subflowUtils = new SubflowUtils();
var inputs = subflowUtils.getSubflowInputs(current.sys_id);
gs.info('Subflow Inputs: ' + JSON.stringify(inputs));
})(current, previous);
Ensure you have proper permissions and roles to access the sys_flow_context table and execute the Script Include.
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2024 10:45 PM
Hi @Yashsvi
Are variables stored on the flow engine contexts table? I get a return value of undefined.