SuiteScript 2.0 Error: no method getTime()

To get the date on a date or datetime field from a record such as that of startdate or lastmodifieddate, the string output from record.getValue() needs to be converted first to a date using N/format module’s format.parse() method.

require(['N/currentRecord', 'N/format'], function (nCurrentRecord, nFormat) {‌
    var currentRecord = nCurrentRecord.get();


    var lastModifiedDateString = currentRecord.getValue({‌
        fieldId: 'startdate',
    });


    var lastModifiedDateObj = nFormat.parse({‌
        value: lastModifiedDateString,
        type: nFormat.Type.DATE
    })


    console.log(lastModifiedDateObj.getTime());
});

Leave a comment

Your email address will not be published. Required fields are marked *