Hello. How could we notice if the address is chang...
# suitescript
b
Hello. How could we notice if the address is changed in customer? maybe using UE script? I tried to compare oldrecord and newrecord but it didn't work. Seems like that is due to address is subrecord
n
can you do
Copy code
function afterSubmit(context) {
  if (context.type === context.UserEventType.EDIT) {
    var newRecord = context.newRecord;
    var oldRecord = context.oldRecord;

    var newSubrecord = newRecord.getSubrecord({
      fieldId: 'addresssubrecord'
    });
    var oldSubrecord = oldRecord.getSubrecord({
      fieldId: 'addresssubrecord'
    });

    var newAddress = newSubrecord.getValue('address');
    var oldAddress = oldSubrecord.getValue('address');

    // Check if the address has changed
    if (newAddress !== oldAddress) {
      // do stuff
    }
  }
}
just swapping out the getSubrecord field for wherever the address subrecord is
b
@Nathan L I tried that code but it didn't work Both of them shows same thing, the changed one
s
you might need to try adding the code to a custom address form (which unintuitively runs server side as well as client side IIRC)
b
Thank you @Shawn Talbert
n
@Nathan L If I remember correctly, the address change is recorded/captured in beforeSubmit (only). Can you try that?
@Shawn Talbert I didn't understand your reply. Are you saying if we apply a client script to address form it runs from server-side changes as well?
b
what did your attempt look like in code