Your validation failure is caused by three interconnected issues with custom SuiteScript validation, project type handling, and error logging. Here’s the comprehensive solution:
CUSTOM SUITESCRIPT VALIDATION FIX:
Your validation script lacks proper error handling and field availability checks. Replace your current validation with this robust implementation:
try {
var projectType = record.getValue('custbody_project_type');
var projectRecord = record.getValue('job');
if (!projectRecord) return {success: true};
if (!projectType) projectType = getProjectType(projectRecord);
} catch(e) {
log.error('Validation Error', e.toString());
return {success: false, message: 'System error'};
}
The key is checking field availability before validation. Your original script assumes custbody_project_type is always populated, but T&M projects may have this field set through different workflows or timing. Implement a fallback function that loads the project record directly to retrieve the type if the custom field is null.
PROJECT TYPE HANDLING SOLUTION:
T&M projects require special handling because their project type values may be stored differently than fixed-price projects. The issue is that NetSuite’s project type field can have different internal IDs versus display values. Your comparison ‘T&M’ is checking against the display text, but the field might contain the internal ID ‘2’ for Time & Materials projects. Modify your validation to check both:
Load the project record within your validation script using record.load with the job field value. Then access the native project type field (not your custom field) using projectRec.getValue({fieldId: ‘projecttype’}). This returns the internal ID. Create a mapping object: var projectTypes = {‘1’: ‘Fixed’, ‘2’: ‘T&M’, ‘3’: ‘Time Only’}. Use this mapping to properly identify T&M projects regardless of how the custom field is populated. This approach handles cases where the custom field isn’t yet populated during workflow execution.
WORKFLOW ERROR LOGGING IMPLEMENTATION:
NetSuite’s default workflow logs don’t capture script-level errors effectively. Implement comprehensive custom logging:
Create a custom record type ‘Validation Error Log’ with fields: Record Type, Record ID, Project Type Value, Error Message, Stack Trace, Timestamp. In your validation script, wrap all logic in try-catch blocks and log to this custom record on any failure. Use log.audit for successful validations and log.error for failures - these appear in Script Execution Log with full context. Add this at the start of your validation function: log.audit(‘Validation Start’, 'Record: ’ + record.id + ', Project: ’ + record.getValue(‘job’)).
For the workflow itself, add a ‘Send Email’ action that triggers on validation failure, including the error details in the email body. This provides immediate visibility when validations fail. Configure your workflow to write validation results to a custom field on the requisition record (custbody_validation_status) so users can see why their requisition is stuck.
ROOT CAUSE AND PREVENTION:
The fundamental problem is timing - your validation runs before project-related fields are fully populated. Move your validation to a later workflow state (after project assignment is confirmed) or implement a conditional validation that only runs if the project type field is populated. Add a workflow condition: IF custbody_project_type IS NOT EMPTY, THEN run validation script. This prevents validation failures on incomplete records while still enforcing rules when data is available.