Scruffy
11/02/2021, 4:42 PMvar startDate = objRecord.getValue('startdate');
and get the same error. Netsuite really doesnt like it when you try to reference the start and end dates on Work Orders.
/**
*
*
* Applied to Work Orders
*
* Script Function: Before Submit of a Work Order, Fills custom hidden Date fields for Start and End dates so that these values an be printed in advanced PDFs.
*
*
* @NScriptType UserEventScript
* @NApiVersion 2.X
* @NModuleScope Public
*/
define(['N/record','N/log'], function (record, log) {
function beforeSubmit(context){
if (context.type !== context.UserEventType.EDIT) return; //Trigger on edited WO
var objRecord = context.Record; //Create object
var startDate = objRecord.getValue({'fieldId':'startdate'});//get the text of the start date
var endDate = objRecord.getValue({'fieldId':'enddate'});
var startDateString = startDate.toLocaleDateString("en-US");
var endDateString = endDate.toLocaleDateString("en-US");
//var numLineItems = objRecord.getLineCount({sublistId: 'item'});
// var objSubRecord = objRecord.
if (!startDate || !endDate){
log.debug({
title: "!date Check",
details: "No dates"
});
return;
}else{
objRecord.setValue('custbodycust_start_date', startDateString);
objRecord.setValue('custbodycust_end_date', endDateString);
}
}
return {
beforeSubmit : beforeSubmit
}
});
stalbert
11/02/2021, 4:43 PMstalbert
11/02/2021, 4:43 PMcontext.newRecord
?Scruffy
11/02/2021, 4:44 PMstalbert
11/02/2021, 4:45 PMnewRecord
is the record with the fields set right before save (in the case of beforeSubmit()
)stalbert
11/02/2021, 4:46 PMoldRecord
is the record with values prior to updatesScruffy
11/02/2021, 4:47 PMstalbert
11/02/2021, 4:49 PMoldRecord
will be undefined IIRC