How can i compare two record have same/duplicate ID and sum of that 2 same record/duplicate ID record in microflow ?

0
I'm fetching data from API's and storing in one entity but what is happening now is i'm getting duplicate ID name and all the data are nearly same but just quantity is different and like that records are getting created with duplicate of ID's. i want to compare the ID's and if ID's are same then i want to sum of the records and show only one record in table. Anyone have any idea about this please help me to resolve this issue. thanks in advance!
asked
2 answers
2

Hi Ajay Phalke

I think you are looking for grouping this can be done in a microflow:

1- Create a non-persistable with the attributes you need I think it will be ID, quantity,...etc

2 - after you get the response of the API you can use a sort list operation to sort it by ID

3- then get the head of this sorted list

4- Create a variable to save the ID of the head lets name it ID

5- Create a list of the non-persistable entity you created name it FinalList to return it in the end event.

6- Create a list of the same sorted list type called ListToAggregate.

7-use a loop to iterate over all sorted objects with a decision if iterator/id = variable you created if true then use change list activity to add the object to the created list.

8- if false aggregate the list then create an object to the non-persistable entity to save the ID and the aggregated attribute then add it to the finalist then clear the ListToAggregate change the variable ID value of the new iterator then add it to ListToAggregate.

Screenshot 2024-01-16 112857.pngScreenshot 2024-01-16 112923.pngScreenshot 2024-01-16 112940.png

Please if this does the job recommend this answer as accepted answer

answered
0

You'll need to apply some extra logic for that during the microflow that calls the API. For each record you retrieve from the API, you'll need to check whether this record exists by retrieving from your local database by its ID. If it exists, you can add the sum of the records to the existing object. If it doesn't exist yet, you can create a new object. Afterwards, commit all objects to the database to store the results. 

answered