Has anyone implemeted or configured script action, please help me with Scenario

Vivek Bakare
Tera Contributor

Has anyone implemeted or configured script action, please help me with Scenario

_ want to know how it is configured and how  it works

3 REPLIES 3

Ankur Bawiskar
Tera Patron

@Vivek Bakare 

It's simple

-> create event with or without table

-> have script action with your script and linked to above event

-> ensure you trigger your event created in step 1 using gs.eventQueue() or gs.eventQueueScheduled()

-> once the event is processed the script action will run it's script as it's listening to that event

Script actions 

Script Action: A Practical Example! 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

ajmalmuhamm
Tera Contributor

HI @Vivek Bakare ,

 

Yes. If you mean a Script Action in Flow Designer/Workflow Studio, it is basically a reusable custom Action containing a Script step. It is useful when the OOB Flow Designer actions cannot perform the logic you need. ServiceNow's current documentation describes the Script step as server-side JavaScript with separate inputs and outputs.

Simple example scenario

Suppose you have a Flow triggered when an Incident is created, and you want to calculate a value based on the Incident priority.

For example:

If Priority = 1 → return "Critical"
If Priority = 2 → return "High"
Otherwise → return "Normal"

You could create a reusable custom Action called Calculate Incident Severity.

How it works

Flow → Custom Action → Script Step → Output → Next Flow Action

1. Create the Action

Go to:

Workflow Studio → Actions → New

Create:

Action name: Calculate Incident Severity

Add an input:

  • Label: Incident
  • Name: incident
  • Type: Reference
  • Reference table: Incident [incident]

Then create an output:

  • Label: Severity
  • Name: severity
  • Type: String

ServiceNow allows Action inputs to receive dynamic data pills from the Flow, while outputs become available as data pills for subsequent steps.

2. Add a Script step

Add:

Action Outline → Steps → Add → Script

The script can be:

 

 
 
(function execute(inputs, outputs) {
 
var incident = inputs.incident;
 
if (incident.priority == '1') {
outputs.severity = 'Critical';
} else if (incident.priority == '2') {
outputs.severity = 'High';
} else {
outputs.severity = 'Normal';
}
 
})(inputs, outputs);
 

 

 

The important part is:

 

 
 
inputs.incident
 

 

 

This receives the value passed into the Action.

And:

 

 
 
outputs.severity
 
 

returns the result to the Flow.

This input/output model is the standard way Script steps communicate with the rest of Workflow Studio.

3. Use the Action in your Flow

Your Flow could look like:

Trigger: Incident → Created

Calculate Incident Severity

Input:

Incident → Trigger → Incident

Update Record

Set:

Severity → Calculate Incident Severity → Severity

So instead of putting the JavaScript directly into every Flow, you now have a reusable Action.

When should you use a Script Action?

I would use one when:

  • OOB Flow actions don't provide the required logic.
  • You need complex GlideRecord processing.
  • The same logic will be reused in multiple Flows.
  • You need to return calculated values to the Flow.

For very small transformations, ServiceNow recommends using inline scripts or transform functions instead of creating a custom Action. For reusable or complex logic, a custom Action/Subflow is generally more appropriate.

Also, test the Action independently before using it in the Flow. Workflow Studio provides an Action Test option and execution details so you can verify the input and output values.

If you're learning ServiceNow, this is actually a good exercise to understand Flow Designer + Action Inputs + Script Step + Action Outputs together.

Ehab Pilloor
Giga Sage

Hi @Vivek Bakare,

 

Script Action is run when an event is triggered. You can create an event, use it in your Script Action, trigger the event and run the script action.

 

Sharing a video I found useful.

https://www.youtube.com/watch?v=M3PXXMYv2JQ&pp=ygUYc2NyaXB0IGFjdGlvbiBzZXJ2aWNlbm93

 

Please Accept this response as Solution if it assisted you with your question & Mark this response as Helpful.

 

Kind Regards,

Ehab Pilloor

This ServiceNow script action video will give you understanding on below topics: 1. What is Script Action in ServiceNow ? 2. How to call Script Action for e.g. in business rule or in any other server side script like script include, workflow, UI action etc.? 3. What are the Benefits of Script ...