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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,237)