Compare the two record fields if any change
Question
Application Type
Reactive

Hi,

I have a use case like one temporary entity say Temp1 having records in thousands (fields around 40).

I have another permanent entity say Entity1 having same structure like Temp1 (fields around 40) 

Temp1 => id, Field1, Field2,...........Field40, column1, column2, createdOn

Entity1 => id, Field1, Field2,...........Field40, column1, column2, createdOn

I wanted to process Temp1 entity and check with Entity1 records if that Id is exist in Entity1 then wanted to check if anything is change for Field1, Field2,...........Field40 only if change the Create record in Entity1.

So basically how do we compare some of the fields from the entity for such a bulk data.

Thanks in Advance.


Hi Rohan,

If I understood your question correctly, I believe that you can assign both records to a variable and assign them the same CreatedOn value, and then convert each variable to JSON and compare them directly.

Does this suit your case?


Best regards,

Manuel

HI Manuel Rodrigues

Thanks for your comment but I want to compare only Field1, Field2,...........Field40 

Thanks

The proposed solution of Manuel is still the way to go, if you want maximum flexibility en efficiency.


You can create another structure with copy pasting Temp1 strcture and leave out the fields you dont want to compare.


Assign both entities to a variable of the new structure type and then convert to json and do a text compare.



Hi Rohan,

I guess you can create your query as follows
Select * from Temp1
inner join Entity1 on Temp1.id=Entity.Id
where Temp1.field1<> Entity.field1 or Temp1.field2<> Entity.field2 and so on

I think if id already exists then you need to apply the update and not create.
and create aggregate or SQL queries with the above query and run update

or if I see the second case of yours you want to add the record in entity1 which not available yet and also if changes exist in both cases you want to upsert data in entity1 then your query will be as follows

I guess you can create your query as follows
Select * from Temp1
left join Entity1 on Temp1.id=Entity.Id
where Entity1.id=null or Temp1.field1<> Entity.field1 or Temp1.field2<> Entity.field2 and so on

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.