
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 12-28-2024 02:19 AM
We often hear about and occasionally implement this feature in ServiceNow. I would like to explain it today with a practical example 😎.
What is Script Action:
A Script Action in ServiceNow is a server-side script that gets executed in response to specific events within the platform
You can call it from server-side scripting supported configurations (ex: Business Rules, Workflow scripts, fix scripts, UI actions, flow designer scripts etc…)
When to use it?:
Use Script Actions when you need to trigger specific actions automatically in response to events, such as record changes or system events. They are ideal for scenarios where consistent and timely execution of tasks is critical, such as sending notifications or updating related records.
Example:
Let's say your organization or client has set up governance around the update set migration process, and it should happen only through update source process, not the import/export method.
If anyone or any team deviates and commits update sets through the import/export process, Update committed update set description and Notify the System Admins with a notification.
How is it done?? lets see!
Step 1: Create an event in the registry table under System Policy > Events
Step 2:Set an appropriate name and select the remote update table name "sys_remote_update_set"
3)Create a business rule to track the update set commit and call the event created in the first step.
Script :
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
gs.eventQueue('update_set_commit_without_source', current, current.getUniqueValue()); //Trigger the script action to update the description of the committed remote update. This will also send an email to the system admins to notify them that the update set has been committed without a source.
})(current, previous);
4)Create a Script Action as below:
System Policy > Script Actions
Create a script action by selecting the event name created in step 1 and add the logic below to get details from the event and update the committed update set with a description by appending "This has been committed without a source."
Make sure you activate the script action because it is unchecked by default.
Script:
var remoteUpdatesetSysid = event.parm1; //get commitetd remote update set sys_id
var remoteUpdate = new GlideRecord("sys_remote_update_set");
remoteUpdate.addQuery("sys_id", remoteUpdatesetSysid);
remoteUpdate.query();
while (remoteUpdate.next()) {
gs.eventQueue('notify_update_set_commit_without_source', remoteUpdate); //Send a notification to the admin team
remoteUpdate.setValue("description", remoteUpdate.getValue('description')+"\n"+"This has been committed without a source by :"+" "+remoteUpdate.getValue('sys_updated_by')); //update the committed description to track
remoteUpdate.update();
}
5)Create a new event for notification (refer step 1) and use the event name to call the notification
Call the event
Add subject and email details:
Add admin groups to be notified, or you can add individual admins or use script logic if required!
Let's see the output:
1)Retrieving an update set through the import/export method.
2)Lets preview and commit the update set
Description has been updated 😍
Notification: 😍
To notify system admins!
You can debate that we can also use an Async Business Rule. Yes, you're right, However, I am trying to explain how a Script Action is decoupled from records and can perform various actions with an example and how to set it up.
Here are some of the differences between an Async Business Rule and a Script Action
Feature | Script Action | Async Business Rule |
Trigger | Event Based | Record Operations (Insert, Update, Delete and Query) |
Execution Context |
Runs asynchronously via the event queue. |
Runs asynchronously after the transaction completes. |
Use case | Background tasks, Integrating with external systems during data sync/update. |
Post-transaction updates, related record processing. |
Scope | Decoupled from records | Tied to specific table and record operations |
Thank you,
Hemanth
ServiceNow MVP 2024 and ServiceNow Community Rising Star 2022 & 2023
My other articles :
A Quick Guide to Adding a Wizard Section to a Catalog Item in Catalog Builder!
Set different “From” and “Reply To” emails for the Native and Flow designer Emails/Notifications.
Read .CSV formatted files in ServiceNow
Automate Assessment/Survey Testing with ATF(Including Multiple Option,Attachments &Reference fields)
Set up interactive filter on UI builder (for data visualization reports and List records)
Set Up "Step Based Request Fulfillment" for Catalog Items
Need to know about Schedules and Define them in SLAs
My ServiceNow Share Projects:
Return Assessment Feature in ServiceNow
Add signature and update fields to a fillable PDF document
Get Record URL action in the flow designer (Use it in the Send Email action)
Custom Generic Flow Action to Create Assessment
- 7,490 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Great work! I've used Script Actions in the past when Process A can launch Process B, but only sometimes.
Process B is really its own thing, so I don't want massive branches or subflows in Process A.
Its also fun to note that events can be catalysts for both Script Actions and Notifications.
So in your example you could take the extra event out of the script, and have your notification fire on the same event as the Script Action.
Now if only Flow Designer could have events as triggers...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
ANOTHER EXAMPLE of event based process launching.
A past employer had an IT coms team responsible for talking to the rest of the organization with respect to "high visibility STUFF". Think major incidents, high impact problems, emergency or failed changes, big upcoming releases, project milestones etc. A wide variety of task types could trigger a com-team task.
Each of those processes could invoke a "com.team.task.needed" event, feed important info via parameters, and have script action create the necessary task for com-team.
"But Uncle Rob, if I could launch the event in code, I can create the task there too"
Yes, BUT that's 10+ lines of code every single time you want to do it (I listed 5 scenarios).
VS, write the com-task builder code once, and feed it parameters from an event that can launch from multiple sources.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Uncle Rob Thank you!
That’s correct I could have used the same event to trigger the notification but I thought
1)let’s do everything in the script action.
2)Fire the notification little late in the action 🤩 (a few milliseconds)
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Hemanth M1
Is there any way to roll back an action performed by a Script Action?
I could not find any relevant information in the ServiceNow documentation.
Could you please guide me on this?
Thank you.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is extremely informative and helpful - thank you.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is really helpful and informative. Thanks for sharing.