How to add/replace data from one entity to another using a loop?

0
I have this loop microflow in the making of replacing/adding data from "Exclusivity_Data_Import" entity into the "Excel_Static" entity. How do I make a loop to check if a row exists in "Excel_Static" and if it's the same, and if not, replace it. And if it doesn't exist at all, create a new entry. Also, how do I make a XPATH constraint using the association I made between those two (the primary key is each accounts SAP number). How do I change "Excel_Static" after going through all of this?
asked
2 answers
0

You will need to perform the actions to check the data.

In the past I created a java action that created a checksum of all the attributes of the source and target. On the target you store the checksum for the attributes, calculate the checksum for the iterator and then try to retrieve the object. If found this is the same, if it can't be found you need to create the record. You might need to include the associations as well or check them separately when the record is found and no changes are made to the attibutes.

Hope this helps in finding a solution.

answered
0
  • Iterate Through the Source: Use a loop (for, foreach, or while) to go through every element in the source entity.

  • Determine the operation:

    • Replace: If the target already has a corresponding item, update it with the new value.

    • Add: If the item doesn’t exist in the target, insert or append it.

  • Assign or Update: During each iteration, assign the source value to the target. In many languages, this can be done via simple assignment.

  • Handle Data Types Appropriately: Make sure you consider whether you need a shallow copy (copying references) or a deep copy (duplicating the data itself), especially if your items are objects.

Example Pseudocode:

 

for each item in sourceEntity:   

key = item.identifier   

if key exists in targetEntity:       

targetEntity[key] = item.value  // Replace existing data    else:       

targetEntity.add(key, item.value) // Add new data

 

Example JavaScript:

 

 

let source = { a: 1, b: 2, c: 3 };

let destination = { a: 10, b: 20 };

// Iterate over each key in the source object

for (let key in source) {   

if (source.hasOwnProperty(key)) {       

// Replace or add the data       

destination[key] = source[key];   

}

}

console.log(destination);

// Output: { a: 1, b: 2, c: 3 }

 

Example Python:

 

 

source = {"a": 1, "b": 2, "c": 3}

destination = {"a": 10, "b": 20}

for key, value in source.items():   

destination[key] = value  # This will add new keys or replace existing ones

print(destination)

# Output: {'a': 1, 'b': 2, 'c': 3}

 

 

I provided you all with the scenarios you can use; you can use whatever language for your error or problem.

 

answered