diff --git a/Server-Side Components/Transform Map Scripts/Check if the Import file is valid/README.md b/Server-Side Components/Transform Map Scripts/Check if the Import file is valid/README.md new file mode 100644 index 0000000000..f9e06ed262 --- /dev/null +++ b/Server-Side Components/Transform Map Scripts/Check if the Import file is valid/README.md @@ -0,0 +1,18 @@ +**Example use Case:** + +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. + +**Risk:** + +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. + +**Solution:** + +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: + +1. Abort the transformation process. +2. Automatically raise a ticket to the responsible team for investigation.(Optional) + + + +This ensures that the existing vendor data in ServiceNow remains unchanged until the issue is resolved. diff --git a/Server-Side Components/Transform Map Scripts/Check if the Import file is valid/script.js b/Server-Side Components/Transform Map Scripts/Check if the Import file is valid/script.js new file mode 100644 index 0000000000..4aa1fa61c4 --- /dev/null +++ b/Server-Side Components/Transform Map Scripts/Check if the Import file is valid/script.js @@ -0,0 +1,32 @@ +/* +When : onStart +Active : True +*/ + +(function runTransformScript(source, map, log, target /*undefined onStart*/ ) { + + var table = import_set.table_name; + var run = new GlideAggregate(table); + run.addQuery("sys_import_set", import_set.sys_id); + run.addAggregate('COUNT'); + run.query(); + while (run.next()) { + var count = parseInt(run.getAggregate('COUNT')); + 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) + ignore = true; + gs.error("File is empty. Hence aborting the transformation"); + + // Creating a ticket to the fulfillment team. This step is optional. + var incident = new GlideRecord('incident'); + incident.initialize(); + incident.short_description = "Import failed due to empty file"; + incident.description = "The incoming file was empty. Please investigate."; + incident.assignment_group = gs.getProperty('Fallback queue'); // Store the resolver group sys id in the system property and use it here. + incident.impact = 3; // Modify as required + incident.urgency = 3; // Modify as required + incident.insert(); + + } + } + +})(source, map, log, target);