How to compare whether two objects are the same

I have a structure of record type A like this:

{id:

other business field:,

relationships:

record Type2: {

id,

A_id,

other business field

}

recordType3: 

{

id,

A_id,

other business field

}

},

After user change the data, I want to check whether the business field is actually modified. What I thought is to traverse the list of this record and construct new objects using the business field, use the new objects to compare. I want to know is this the only way to solve my problem? Is there any easy way can solve this.

 

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Instead of creating new objects you can simply compare the business fields for similarity and depending on output disable/enable the submit button. 

    Keep the data before any changes are made in a variable and keep one variable to do comparison of old data with variable having changes due to user interaction. The output of this variable can build the logic to manage the submit button. Below is an example for reference, 

    a!localVariables(
      local!oldItems: {
        {id:1,item: "Item 1", qty: 1, unitPrice: 10,user:"JAdoe"},
        {id:2,item: "Item 2", qty: 2, unitPrice: 20,user:"AHer"}
      },
      local!newItems: {
        {id:1,item: "Item 1", qty: 1, unitPrice: 10,user:"JAdoe"},
        {id:null,item: "Item 2", qty: 2, unitPrice: 20,user:"PTer"}
      },
      /*If true, disable button*/
      and(a!isNullOrEmpty(symmetricdifference(local!oldItems.item,local!newItems.item)),
      a!isNullOrEmpty(symmetricdifference(local!oldItems.qty,local!newItems.qty)),
      a!isNullOrEmpty(symmetricdifference(local!oldItems.unitPrice,local!newItems.unitPrice)))
    )
    

  • +1
    Certified Lead Developer
    in reply to Harsha Sharma

    I'd like to note an important corner case here - if the user swaps two values between rows but otherwise makes no changes, such as changing the Unit Price of row 1 to 20, and for row 2 to 10 - the Symmetric Differences will all still turn up the same, and the form will thus (incorrectly) assume changes have not been made.

    Edit: to solve this, you could take a similar approach but instead of comparing merely the original arrays in a manner that ignores positional context of individual data items, you could easily assemble easy-to-compare arrays of text items, where each text item in the array holds all the data we care about.  Then when any update is made, including an identical swap of data between rows, it's reflected in the symmetricDifference() result:



Reply
  • +1
    Certified Lead Developer
    in reply to Harsha Sharma

    I'd like to note an important corner case here - if the user swaps two values between rows but otherwise makes no changes, such as changing the Unit Price of row 1 to 20, and for row 2 to 10 - the Symmetric Differences will all still turn up the same, and the form will thus (incorrectly) assume changes have not been made.

    Edit: to solve this, you could take a similar approach but instead of comparing merely the original arrays in a manner that ignores positional context of individual data items, you could easily assemble easy-to-compare arrays of text items, where each text item in the array holds all the data we care about.  Then when any update is made, including an identical swap of data between rows, it's reflected in the symmetricDifference() result:



Children
No Data