Creating Custom Actions for Controlled Data Load and Transformation in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 04:36 AM
Overview
In many real-world business processes, especially those dealing with bulk data uploads, it’s essential to validate the data before loading it into the system. Furthermore, certain actions—such as triggering a transform map—should only happen after manual review and approval.
In this article, we'll walk through the design of a ServiceNow Flow using custom Scriptable Flow Actions that:
- Loads a file into a staging table using a data source
- Validates records using a Script Include
- Waits for agent approval
- Upon approval, triggers a transform map
We’ll also cover how we modularized this logic using two custom actions:
- Trigger Data Source (provide any name for custom action)
Purpose:
Load the file into a staging table using the selected Data Source and validate each record using a Script Include.
Inputs:
Input 1:Input Name: dataSource
Type: Reference (Data Source)
Description: Points to the pre-configured Data Source used for this upload
Input 2:
Input Name: request_id
Type: String
Description: Sys ID of the catalog request
Output Name: Records of the data source which to be given as input for trigger action from flow.
2.Trigger Transform Map (provide any name for custom action)
Inputs: Type: Records of data source
Step-by-Step Breakdown
Step 1: Upload and Parse File Data
The process begins when a catalog request is submitted with an Excel/CSV file containing data.
Step 2: Custom Action – Trigger Data Source
This action is a Script step that:
- Loads the uploaded file into the staging table
- Uses GlideImportSetLoader to create an import set
- Associates the import set with the request
- Invokes a Script Include to validate data
var loader = new GlideImportSetLoader();
var importSetGr = loader.getImportSetGr(dataSource1);
loader.loadImportSetTable(importSetGr, dataSource1);
importSetGr.setValue('u_request_id', inputs.request_id);
importSetGr.update();
// Run script include validation
var rows = new GlideRecord('Staging table');
rows.addQuery('sys_import_set', importSetGr.sys_id);
rows.query();
while (rows.next()) {
new x_msxin_cb.fleetProfileAJAX().checkVinActionValidity(rows); //script include where the validation is performed
}
This ensures invalid records are flagged before they ever hit production data tables.
Step 3: Ask for Approval
After data is loaded and validated, we pause the flow and route the request for approval using the Ask for Approval flow logic.
This allows agents or managers to inspect the parsed and validated data.
Step 4: If Approved → Proceed to Transformation
If the agent approves the request, we proceed to our second custom action.
If approved the next action in the flow for transforming is triggered.
Step 5: Custom Action – Trigger Transform Map
This custom Scriptable Flow Action:
- Retrieves the Import Set Run for the loaded file
- Triggers the transform map using GlideImportSetTransformer
function doTransform(set) {
var importSetRun = new GlideImportSetRun(set.getUniqueValue());
var importLog = new GlideImportLog(importSetRun, set.data_source.name);
var ist = new GlideImportSetTransformer();
ist.setLogger(importLog);
ist.setImportSetRun(importSetRun);
ist.transformAllMaps(set);
}
The entire transformation process is now conditionally controlled, based on:
- Successful data load
- Script Include validation
- Agent approval
Step 6: If Rejected → Terminate Flow
If the agent rejects the request, we:
- Skip the transformation step
- Log or notify the requester about the rejection
- End the flow
Key Benefits of This Approach
1) Custom Scriptable Flow Actions (Trigger Data Source and Trigger Transform Map) can be reused across other flows.
2) Only clean and reviewed data proceeds to transformation.
3)Using a Script Include for record-level validation enhances maintainability and auditability.
4) Approval-Driven Automation
Conclusion
This setup showcases how Flow Designer + Scriptable Flow Actions + GlideImport APIs can power a sophisticated, secure, and modular data import pipeline. By structuring your flows this way, you reduce the risk of importing bad data, ensure accountability via approvals, and gain the flexibility to scale your data operations.
Have questions or want to share your approach? Drop your thoughts in the comments!
- 300 Views