I would like to get a list of all changed fields w...
# ask-stanley-ai
n
I would like to get a list of all changed fields with respective ids and new values on saveRecord client script event. I think I can use currentRecord.getField(...) if I knew what fields have changed. So, is there a way to get a list of changed fields on the event?
c
AI generated answer (using internal Slack threads):
In order to get a list of all changed fields with respective ids and new values on saveRecord client script event, you can use the
fieldChanged
event in SuiteScript 2.0. This event is triggered whenever a field is changed in the UI. Here is a sample code snippet that demonstrates how to use the
fieldChanged
event:
Copy code
javascript
function fieldChanged(context) {
    var currentRecord = context.currentRecord;
    var fieldName = context.fieldId;
    var newValue = currentRecord.getValue(fieldName);
    console.log('Field: ' + fieldName + ', New Value: ' + newValue);
}
In this code,
context.fieldId
gives you the id of the field that was changed, and
currentRecord.getValue(fieldName)
gives you the new value of the field. However, please note that this will only track changes made in the UI and won't track changes made through CSV imports or other bulk operations. Also, this won't track changes made to sublist fields. For sublist fields, you would need to use the
sublistChanged
event. ****** 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.852280617
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.848263562
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.8436113
Please provide your feedback on this answer.