Retrieve subflow input values through script

Dazler
Mega Sage

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.

9 REPLIES 9

Yashsvi
Kilo Sage

Hi @Dazler,

please check below links:

https://www.servicenow.com/community/developer-forum/access-subflow-inputs-from-activity-script/m-p/...

Thank you, please make helpful if you accept the solution. 

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.

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. 

Hi @Yashsvi 

 

Are variables stored on the flow engine contexts table?  I get a return value of undefined.