cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Advocate III
Advocate III

Creating multiple target list items based on values in the source list

I have a requirement for automatically creating multiple items in a target list, whereby the number of items to be created and their contents are driven by a source list, sort of transpose and expand.

 

Data in SourceQ1Q2Q3Q4
A12,501,5
B0120
     
Result in Target    
A-Q11   
A-Q21   
A-Q21   
A-Q20,5   
A-Q41   
A-Q40,5   
B-Q21   
B-Q31   
B-Q31   

 

In a nutshell, for each item in the source list, create as many items in the target list as specified in each column.

If column Q2 for item A is 2.5, I need 3 items in the target list, 2 with a value of 1 and the 3rd with a value of 0.5.

I figured out the innermost part by setting a variable, then a do until loop variable <= 0 with the output formula

if(greaterOrEquals(variables('thisQuarterValue'),1),1,mod(variables('thisQuarterValue'),1))

and then decrement the variable by 1.

 

That works just fine, but now I need to assure that new items are only created for the item that was modified in the source list and triggered the flow. I applied an array filter after the Get items action, tried comparing both, Title and Title Id from  "when an item is created or modified"  with Title resp. Title Id from the Get items array, but to no avail, the workflow completes with no error but creates the new records for both, row A and row B in the source list, no matter which one I modify to trigger the flow.

 

Any suggestion? Thank you!

 

3 REPLIES 3
Highlighted
Advocate III
Advocate III

Re: Creating multiple target list items based on values in the source list

No way to get this to work, Apply for each affected all records from Get items.

 

Filter Array.png

 

Instead, added another condition within the Apply for each section:

 

Condition2.png

 

So this does the trick just fine, but not very elegantly. What could be wrong with my Filter Array?

 

Highlighted
Community Support
Community Support

Re: Creating multiple target list items based on values in the source list

Hi @Beat,

 

Do you want to create new item within the target list for an existing item is modified within your Source list?

Could you please share a screenshot of your flow's configuration?

 

If you could provide more details about your scenario, we would provide a proper workaround for you.

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Advocate III
Advocate III

Re: Creating multiple target list items based on values in the source list

Yes I want to create multiple items in the target list, based on data in source list items, but it's actually triggered when an item is changed in a third list which has a key to items in the source list.

 

So when an item in the triggering list is modified, the flow should make a collection of all matching entries in the source list and then create items in the target list. I figured out the workaround, using another condition within the Apply to each loop, but that's not very elegant, as it will cycle through all items in the source list skipping those that don't match the key from the triggering list.

 

Here the screenshots:

 

trigger and check if status is approved.png

 

If Status equals approved, get items from the Source list and filter the array for items where the title matches the key from the triggering list stored in thisPlanTitle:

 

get items and filter array.png

 

And that's where it fails. The subsequent Apply to each loop will act upon all items in the source list, not only those where the title matches the key from the triggering list.

 

Here the workaround: adding a condition within the apply to each section

 

condition 2.png

 

I then thought well, of course the Filter Array must be within the Apply to each section in order to work!

 

filter array within apply to each.png

But no, that makes of course no sense and didn't solve my issue. So I'm going to keep the Condition within the Apply to each cycle, as long as there are not hundreds or thousands of items it won't matter much, but still I would like to understand why Filter Array after Get Items is not filtering the items correctly.

 

 

 

Helpful resources

Announcements
firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

Join the new Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Users online (9,586)