← Home
🔥0 DAY
0 XP
Flow Designer · Step-by-step

Add a script step in Flow Designer

Short answer

Add Action → Utilities → Script, declare every value the script needs on the Inputs tab, declare what it returns on the Outputs tab, then read them as inputs.<name> and assign outputs.<name> inside the execute() function. A Flow Designer script has no current and no access to flow data you did not pass in as an input.

Where: Flow Designer → Add an Action, Flow Logic or Subflow → Action → Utilities → Script

Steps

  1. 1.Open the flow and add the Script action

    Open your flow, click Add an Action, Flow Logic or Subflow → Action, then choose Utilities → Script. The step lands wherever your cursor is in the flow, so add it after the step whose output you need.

  2. 2.Declare typed inputs on the Inputs tab

    Click Create Variable / the Inputs tab and add one input per value the script needs. Give each a type (String, Reference, True/False, Date/Time). Then drag the upstream data pill — trigger record sys_id, a lookup result, a flow variable — into the matching input field. Nothing outside these inputs is visible to the script.

  3. 3.Declare the outputs you want to return

    On the Outputs tab, add one output per value downstream steps need, again typed. Outputs are the only way a Script step hands data back to the flow.

  4. 4.Write the script against inputs and outputs

    The body is wrapped in an execute(inputs, outputs) IIFE. Read with inputs.<name>, write with outputs.<name>. Always convert Glide values with toString() or getValue() before assigning them to a String output, otherwise you store a GlideElement object.

    (function execute(inputs, outputs) {
      var gr = new GlideRecord('incident');
      if (!gr.get(inputs.incident_sys_id)) {
        outputs.found = false;
        return;
      }
    
      outputs.found = true;
      outputs.short_desc = gr.getValue('short_description');
      outputs.priority = gr.getValue('priority');
      outputs.assignee_email = gr.assigned_to.email ? gr.assigned_to.email.toString() : '';
    })(inputs, outputs);
  5. 5.Use the outputs downstream

    In the next step's field, open the data pill picker and expand your Script step — each declared output appears as a pill. Branch on it with Flow Logic → If when the script returns a boolean.

  6. 6.Test and read the log

    Click Test (or Run Test), then open the execution details. Each step row shows its input and output values; gs.info() lines from the script appear in the step log and in System Logs → All filtered on the flow name.

    (function execute(inputs, outputs) {
      gs.info('[flow-debug] incident=' + inputs.incident_sys_id);
      // ... work ...
    })(inputs, outputs);

Common mistakes

  • Referencing current or previous — they do not exist in a Flow Designer script. Pass the record sys_id in as an input and re-query it.
  • Returning a value with return or gs.print instead of assigning outputs.<name> — the flow sees nothing.
  • Assigning a GlideElement to a String output (outputs.x = gr.short_description) — use getValue() or toString().
  • Cross-scope calls failing silently: a Script step in a scoped app cannot reach a global Script Include unless that include is Accessible from: All application scopes.
  • Long-running loops in a Script step. Flow Designer steps run in a transaction — move bulk work to an Action with a proper query step or a scheduled job.

FAQ

Can a Flow Designer script step use current?

No. current is only available in Business Rules and similar server-side contexts. In Flow Designer you pass the record (usually its sys_id) into a declared input and re-query it with GlideRecord.

How do I return multiple values from a script step?

Declare one output per value on the Outputs tab and assign each one inside execute(). There is no limit on the number of outputs, and each appears as its own data pill downstream.

Where do gs.info() messages from a script step go?

To the flow execution details for that step and to System Logs → All. Prefix your messages so you can filter them, for example gs.info('[flow-debug] ...').