<@UFQ6EPNCT> there's most probably a better way. T...
# general
m
@Livio there's most probably a better way. Throwing an error could trigger notification emails, and will cloud over real issues. Why can't you just return early from the script? Also you could choose not to run scripts/workflows in a CSV import under advanced settings.
l
Actually first thing i want to ask is: How to check if a record was updated (script 1.0)? And the second question: "Is there any other way to stop an update besides throwing an error?"
m
What type of script?
l
user event script
m
To check if a record was changed you can compare the
oldRecord
and
newRecord
. I think the only way to stop an update is to throw an error.
l
should I do beforeRecord Submit or After Submit?
m
Depends what you are trying to accomplish
If you need to potentially prevent an update then it should be a
beforeSubmit
l
function ValidateRecord(type) { // if the record is inline edited or mass updated, run this script if (type == 'xedit') { var oldRec = nlapiGetOldRecord(); var newRec = nlapiGetNewRecord(); // Get all the field IDs in the record var old_rec_fields = oldRec.getAllFields(); if(oldRec=== newRec){ throw nlapiCreateError('E010','No Changes Made to this record', true) ; } } } What am I doing wrong here cause it is not working at all
b
Using === to compare objects is usually wrong. === checks if the 2 variables refer to the same thing in memory.
You really need to do what I mentioned earlier and use methods like getFieldValue to compare individual values
l
but i do not care about a specific field value - i want to check if the record was updated or not (in general)
b
you don't really have a choice, the way you are comparing records will not get you what you want
l
oh ok. thank you for your help @battk