How to determine a record is edited or not? My r...
# suitescript
s
How to determine a record is edited or not? My requirement : I ve to make the record go through a approval process ,if something is edited in that record . To that I need to know if something is edited in that record . If I use the scriptcontext as 'edit' , what if the user saves the record without doing any changes .? Kindly , Let me know how to achieve this ?
c
Ideally, you would have to check fields that you care about triggering the approval process for changes. Most likely its not ANY edit to the record but certain fields that would require approval. If saving a record where no edits were made and you click OK on the native NetSuite prompt that says "no record changes were made do you want to save anyways?" then it will trigger an edit event.
r
In case of edit, Values of fields you care about in Conext old records are not equal to value in Conext new record fields. In case of create, you don't need to check anything just go through the approval process..
s
The problem is that Ive to check if any field is changed expect that of memo .. It's not possible to check every fields old and new value .. ! @raghav, @creece
r
Log debug the new record object. See where it has data related to fields And then get all fields and iterate over them.
s
Yeah tried that .. but some form fields are also comming as part of the fields. And it is changing on old and new record . So even if you didnot change anything, all the fields won't match . And it fails !
r
You either create an array of field internal Ids you care about, or you create an array of fields you do not care and ignore those fields and iterate over them and compare, I would suggest former over the later. Also one more thing empty fields in old records come as null while empty fields in new records will come as empty string.
👀 1
s
Thanks mate.
c
@shree sashti One thing to watch out for is the difference between EDIT and XEDIT - the latter is used when
record.submitFields
is executed, as well as when list edit is enabled in the UI and in some other contexts. When the record is edited in XEDIT context, field values for fields that aren't being submitted will return as empty, which might confound attempts to validate changes. In this instance, I use
newRecord.getFields()
to see which fields are actually being submitted.
s
Good point @Clay Roper. Noted. Thanks