Recently, a NetSuite script I was working on involved rolling down the default address from a customer record to all associated contacts when the default address was changed or edited. At first, I thought it best to run the script as a field changed event. However, I quickly realized that if changes were made but the user didn’t submit them, I wouldn’t want those changes rolled down. Thus, in changing the script from a Client Side field changed event to a User Event After Submit event, I needed to add a simple function to my script which would compare the old record’s field value with the new record’s in my new After Submit script. Below is the code snippet for this example. Note that the fieldWasChanged function takes field as a parameter; when you call the script in your afterSubmit function, make sure that the internal ID of the field you want it to look at is correct and wrapped in quotes.

function afterSubmit() {

       if (fieldWasChanged(‘defaultaddress’) == true) {

              nlapiLogExecution(‘debug’,‘default address was changed’,);



function fieldWasChanged(field)

       var rcdOld = nlapiGetOldRecord(); // loading the old record 

       var record = nlapiLoadRecord(nlapiGetRecordType(),nlapiGetRecordId()); // loading the new record

       if(rcdOld.getFieldValue(field) != record.getFieldValue(field)) { // compare field values 

              return true;

    } else {

              return false;



For this example, if the default address on the customer record was changed, my afterSubmit script will note this. After I uploaded this script, I deployed it to the customer record, and performed a quick test, changing the customer’s default address and submitting the customer. Below is the execution log for the script after submitting:

NetSuite Execution Log

As you can see, the script correctly logged that the default address was changed. Overall, this simple function can allow you to set conditions for your script’s behavior based on whether or not a field was changed. This can be used to set whether the script should run, log any changes made to sensitive records, and many other applications.

As always, let us know what ways YOU would like to extend NetSuite and how MIBAR can help. Contact us today.

Wait! Before You GoWould you like to talk to a business software expert to answer your questions?

When you schedule a free consultation with MIBAR, you will experience a one-on-one conversation with a business technology expert who is passionate about understanding your unique needs or issues. Schedule a free consultation today at the link below or give us a call at (212) 869-9300.

Learn More
NetSuite Offer: Save $15,000 With Our Limited-Time Discount

If you’ve been evaluating NetSuite, there is no better time to make the switch. With a NetSuite subscription through MIBAR by December 31, 2020, we will offer you 75 hours of professional consulting services for FREE.

Not only can a new ERP system like NetSuite help you reduce operating costs by automating manual processes, but this limited time offer can also help save you a substantial amount of money upfront.