Having issues pulling dates from work orders. I ge...
# suitescript
s
Having issues pulling dates from work orders. I get a "cannot call method 'getValue' for undefined" when the value is clearly defined in the record. What going on? I also tried
var 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.
Copy code
/**
 * 
 * 
 * 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
    }

});
s
context.Record is not what you need.
maybe you meant
context.newRecord
?
s
i think think youre right. I guess i thought you can only do new record on a newly created record but i think im understanding it incorrectly. Its a new record OBJECT right?
s
newRecord
is the record with the fields set right before save (in the case of
beforeSubmit()
)
oldRecord
is the record with values prior to updates
s
i see. Looks like the script didnt fail this time. Will see what has happened. Thanks fam.
s
when creating a brand new record,
oldRecord
will be undefined IIRC
👍 1