The CreatorCon Call for Content is officially open! Get started here.

How Do I Create a Run Script in a Flow

dmullinax
Mega Guru

How do I create a run script in flow designer?

 

In the past we used workflow editor.  There was this activity "run script" where we would broadcast an event to trigger an email notification.

 

An example of the workflow.
workflow.jpg

In the activity, we use an eventqueue that would trigger the email.
run_script_eventqueue.jpg

Given that workflow editor is no longer supported, we are now forced to use flow designer.
"The Workflow Editor is a legacy product to maintain existing workflows already in production. For new use cases and workflows, use the following ServiceNow applications:"

 

In flow designer, I am trying to create that same script to broadcast an event that will trigger an email notification.

 

However, there is no "run script" under the action here:

flow.jpg

Where is the equivalent to "run script?"

6 REPLIES 6

Have you tried the out of box action "Fire Event"?

GaryFawcett1_0-1757903884970.jpeg

 

Nitish Saini
Giga Guru

Hi @dmullinax ,
In Workflow Editor we had the "Run Script" activity where you could just paste in server-side JS and broadcast an event (like gs.eventQueue(...)) to trigger an email notification.

In Flow Designer, things are a bit different:


Options for “Run Script” in Flow Designer

  1. Use the “Action” → “Script” step

    • In Flow Designer, open your Flow.

    • Add an Action.

    • Choose "Script" (under “Utilities”).

    • This allows you to write server-side script directly (similar to Run Script).
      Example:

       
      gs.eventQueue("my.custom.event", current, current.sys_id, gs.getUserID());

      This will fire your event like before.

    2. Create a Custom Action with a Script Step

  • In Flow Designer, go to Action Designer.

  • Create a new Action.

  • Add an Input (if you want to pass in record values).

  • Add a Script step and write your server-side logic there.

  • Save and publish the Action.

  • Now you can use that Action inside any Flow.

  3. Best practice → Use "Fire Event" step instead of custom script
If your only purpose is to fire an event for email notifications:

  • Add the “Fire Event” step in your Flow (available out-of-the-box).

  • Enter the Event name (same as in System Policy → Events).

  • Add parameters (parm1, parm2).
    This does the same thing as gs.eventQueue without needing a script.


Summary:

  • If you want exact Run Script → use “Script” step.

  • If you only need to trigger email notifications → better to use “Fire Event” step (simpler, upgrade-safe)

    Please accept my answer and mark as helpful/correct if it resolves your query.

    Regards, 
    Nitish Saini