Prevent insertion in transform map after validating data

Hm10
Tera Contributor

I am inserting data from Excel to Transform Map from Import Set. I am using OnBefore Script to check for Nodes, If the nodes with a specific id are occurring more than 50 times I don't want the insertion to occur for even a single record in transorm map. This is my OnBefore Script Code but it is inserting all records without checking 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
  var nodeSiteCount = {};
    gs.log("ONBSEFORE");
    var nodeID = source.u_node.toString();
    
    // Initialize or update the count for this node ID
    if (!nodeSiteCount[nodeID]) {
        nodeSiteCount[nodeID] = 1; // Initialize counter for this node ID
    } else {
        nodeSiteCount[nodeID]++;
        if (nodeSiteCount[nodeID] > 50) {
            // Log a message and stop the transform map
            var s = 'Please correct your Excel file and then upload it';

            // Create a new GlideRecord for the Change Request table
            var changeRequestGR = new GlideRecord('change_request');

            // Add a condition to filter records where the number is "4"
            changeRequestGR.addQuery('number', 'CHG0040004');

            // Execute the query
            changeRequestGR.query();

            if (changeRequestGR.next()) {
                changeRequestGR.work_notes = s;
                changeRequestGR.update();
                gs.info('Updated work notes for Change Request ' + changeRequestGR.number);
            } else {
                gs.info('No Change Request found with the number "4"');
            }

ignore=true;
			return;
        }
    }
})(source, map, log, target);
0 REPLIES 0