Skip to content

Commit 725950e

Browse files
onStart Transform script to validate if the incoming file is empty or not (#1944)
* Create Code.js * Create README.md * Add Business rule: Add or remove tag to the ticket * Rename code.js to code.js * Rename README.md to README.md * Adding new UI Action: Generate PDF * Adding new UI Action: Generate PDF * Adding new Background script: Bulk Update of Fulfillment Group References in Published KB Articles * Adding new Background script: Bulk Update of Fulfillment Group References in Published KB Articles * Delete Server-Side Components/Background Scripts/Bulk Update of Fulfillment Group References in Published KB Articles directory * Update Script.js * Update README.md * Update README.md * Delete Client-Side Components/UI Actions/Generate PDF directory * Create script.js * Create README.md * Create script.js * Create README.md * Delete Server-Side Components/Script Includes/Calculate Due date using user defined schedules directory * Create README.md * Add files via upload * Update script.js * Update README.md * Create README.md * Update README.md * Create ui_action_script.js * Create ui_page.html * Create ui_page_client_script.js * Create ui_page_processing_script.js * Update README.md * Add files via upload * Updated the table name ui_page_processing_script.js * Create script.js * Create README.md * Update script.js * Update README.md * Update script.js
1 parent ebd1df6 commit 725950e

File tree

2 files changed

+50
-0
lines changed
  • Server-Side Components/Transform Map Scripts/Check if the Import file is valid

2 files changed

+50
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
**Example use Case:**
2+
3+
Vendor data is periodically imported into ServiceNow via a scheduled data load (import set) sourced from an external application. These files contain only valid vendor records. After the import, any existing vendor records in ServiceNow that are not present in the latest file should be marked as inactive.
4+
5+
**Risk:**
6+
7+
If the incoming file is empty due to an issue in the source application, all existing vendor records in ServiceNow could be incorrectly marked as inactive, resulting in data loss or disruption.
8+
9+
**Solution:**
10+
11+
To prevent this, implement an "onStart" transform script that checks whether the import set contains any data before proceeding with the transformation. If it is found to be empty, the script should:
12+
13+
1. Abort the transformation process.
14+
2. Automatically raise a ticket to the responsible team for investigation.(Optional)
15+
16+
17+
18+
This ensures that the existing vendor data in ServiceNow remains unchanged until the issue is resolved.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
When : onStart
3+
Active : True
4+
*/
5+
6+
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
7+
8+
var table = import_set.table_name;
9+
var run = new GlideAggregate(table);
10+
run.addQuery("sys_import_set", import_set.sys_id);
11+
run.addAggregate('COUNT');
12+
run.query();
13+
while (run.next()) {
14+
var count = parseInt(run.getAggregate('COUNT'));
15+
if (count < 1) { // Check the row count of the latest import job. If it's 0, then abort the transformation and raise a ticket (Optional)
16+
ignore = true;
17+
gs.error("File is empty. Hence aborting the transformation");
18+
19+
// Creating a ticket to the fulfillment team. This step is optional.
20+
var incident = new GlideRecord('incident');
21+
incident.initialize();
22+
incident.short_description = "Import failed due to empty file";
23+
incident.description = "The incoming file was empty. Please investigate.";
24+
incident.assignment_group = gs.getProperty('Fallback queue'); // Store the resolver group sys id in the system property and use it here.
25+
incident.impact = 3; // Modify as required
26+
incident.urgency = 3; // Modify as required
27+
incident.insert();
28+
29+
}
30+
}
31+
32+
})(source, map, log, target);

0 commit comments

Comments
 (0)