Best way to compare the old and new record in a us...
# ask-stanley-ai
r
Best way to compare the old and new record in a user event
c
AI generated answer (using internal Slack threads):
The best way to compare the old and new record in a user event is to use the
scriptContext.oldRecord
and
scriptContext.newRecord
objects in SuiteScript 2.0. These objects are of type
record.Record
and you can use methods like
Record.getValue
to get the value of a field from one to compare to the other. Here is a simple example:
Copy code
javascript
function afterSubmit(scriptContext) {
    var oldRecord = scriptContext.oldRecord;
    var newRecord = scriptContext.newRecord;

    var oldFieldValue = oldRecord.getValue({fieldId: 'your_field_id'});
    var newFieldValue = newRecord.getValue({fieldId: 'your_field_id'});

    if(oldFieldValue !== newFieldValue) {
        // The field value has changed
    }
}
In SuiteScript 1.0, you can use
nlapiGetOldRecord
and
nlapiGetNewRecord
to get the old and new record respectively. When comparing date fields, make sure to compare the time values of the date objects, not the date objects themselves. For example, use
newDateObj.getTime() === oldDateObj.getTime()
, not
newDateObj === oldDateObj
. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.824675262
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.824640632
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.823863268
Please provide your feedback on this answer.