Hello,
I am trying to prevent listing errors by creating a Data Validation Script that would prevent employees from updating the "Classification" Field on Inventory Items (except for Parent SKUs) if the "Item Weight" and "Dimweight" Fields are empty.
Here is what I have tried so far:
Script File
/** * @NApiVersion 2.x * @NScriptType UserEventScript */define(['N/record', 'N/error', 'N/log'], function(record, error, log) { function beforeSubmit(context) { log.debug('Script Triggered', 'beforeSubmit function has been triggered.'); // Only proceed if this is an edit operation if (context.type !== context.UserEventType.EDIT) { log.debug('Exit Condition', 'The script is not running on an edit action, so it will exit.'); return; } var currentRecord = context.newRecord; // Retrieve relevant field values var classification = currentRecord.getValue({ fieldId: 'custitem145' }); var weight = currentRecord.getValue({ fieldId: 'weight' }); var dimWeight = currentRecord.getValue({ fieldId: 'custitem30' }); // Custom field ID for DimWeight var isParentSKU = currentRecord.getValue({ fieldId: 'custitem180' }); // Updated field ID to determine if item is a Parent SKU // Log the retrieved values log.debug('Field Values', { classification: classification, weight: weight, dimWeight: dimWeight, isParentSKU: isParentSKU }); // Allow updates for non-Parent SKUs only if (isParentSKU) { // If custitem180 is checked, it means the item is a Parent SKU log.debug('Parent SKU', 'Item is a Parent SKU; validation is skipped.'); return; } // Check if Classification is changing to start with "Clearance" or "Standard" if (classification && (classification.startsWith('Clearance') || classification.startsWith('Standard'))) { log.debug('Classification Check', 'Classification starts with "Clearance" or "Standard".'); // Validate that both Weight and DimWeight are populated if (!weight || !dimWeight) { log.debug('Validation Failed', 'Either Weight or DimWeight is missing. Throwing error.'); throw error.create({ name: 'CLASSIFICATION_UPDATE_ERROR', message: 'Classification cannot be changed to "Clearance" or "Standard" unless both Weight and DimWeight are populated.', notifyOff: true }); } else { log.debug('Validation Passed', 'Both Weight and DimWeight are populated.'); } } else { log.debug('Classification Check', 'Classification does not start with "Clearance" or "Standard". No validation needed.'); } } return { beforeSubmit: beforeSubmit };});
On the script record: There is nothing in the Execution Log
On the Deployment Record: Nothing in the Execution Log
The Deployment Status is "Testing". I have the Administrator Role. The Deployment Audience is set to "Administrator".
Execution Context: User Event Script
Thanks!