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

Flow: Check SP List for existing item, if not there add new, otherwise update. Keeps adding new items despite item already existing.

Hi all,

I have 2 SP lists, '21-22 PreEnrollment' and '21-22 ClassRoster.' Once a day, I'd like to have a Flow check the PreEnrollment list for any items with today's date in the 'Start Date' field. If the Start Date is today, I want the Flow to then check the ClassRoster list for an existing item (both lists have the same unique ChildID for each item). If the item exists, update the Start Date, otherwise create a new item.

 

I've got it partially working, in that items with today's Start Date will add to the ClassRoster, but instead of updating existing items the Flow just creates a new item. I've been browsing the forum for a few hours now and every solution seems to refuse to work and I'm not sure why.

 

Flow OverviewFlow Overview

 

ODATA Filters for both 'Get Items'ODATA Filters for both 'Get Items'

 

Expression for ConditionExpression for Condition

 

4 REPLIES 4
DamoBird365
Super User
Super User

Hi @susannarae 

 

Your opening PreEnrolls Items looks fine but probably no need for a filter on childid in the get roster as you can filter on the array.  You also want to avoid nested apply to each actions. 

 

Using the method you have attempted, you could create an apply to each on the values from your first get items and then perform a filter array on each item with the 2nd list values in the from of the filter.  If the filter array length is 0, create the item, otherwise update the item.  This would only need 1 apply to each.

 

DamoBird365_0-1618860566200.png

 

Alternatively, how familiar are you with the concept of intersect and except?  You could tackle this by creating an array of intersect where the child id exists in both and an except, appear in one but not the other.  Once you have these two arrays, you can run an apply to each on both arrays and either perform your create or update as necessary.  I did an article on intersect and except here.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

 

 

Your solution seems to be almost perfect, but for some reason Flow keeps adding a second 'Apply to Each' to my 'If no' condition, which then updates and changes the names/info on every kid to match the existing list item. How do I get rid of that unwanted nested 'Apply to Each'?


Hi @susannarae 

 

It will be creating the apply to each based on the dynamic values you are selecting for your update item action, which are presumably part of an array.  If you share a screenshot of your flow and in particular your unwanted apply to each I will try and work out how/why.

 

For your update item ID, you would want to take the ID from your filter array values.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here

 

 

susannarae_0-1618934673207.png

Here is a screenshot of the unwanted Apply to Each as well as the Filter Array. I appreciate your help on this, it's been giving me issues for days now.

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,607)