Power Automate Exchange

Please login or click SIGN UP FOR FREE to create your FlowUG account to join this user group.
Expand all | Collapse all

update list item, or create new item if it doesn't exist

  • 1.  update list item, or create new item if it doesn't exist

    Posted Sep 20, 2018 12:43 PM
    HI - I have an approval list (List 1), that when complete, checks another list (List 2) to see if the same item exists.  If it does, I want the flow to update the existing item in List 2.  If it doesn't exist, I want the flow to create a new item in List 2.  I'm not sure what the best action is to use - currently I am using the 'Apply to each', but the problem is the actions occurs for every line item in List 2, instead of just checking the full list, and performing the update/new item action once.  Any ideas?  Thank you in advance.
    thumbnail image


    ------------------------------
    Adam Cain
    eLearning Manager
    Granite Bay CA
    9162769608
    ------------------------------


  • 2.  RE: update list item, or create new item if it doesn't exist

    Microsoft Power Platform Team
    Posted Sep 21, 2018 06:41 AM
    Hi Adam,

    Assuming there is some unique value that can be used to search, you should be able to use the SharePoint action for "Get Items" and then supply an oData filter to specify the item in List 2... if you get a return, then the item exists and if not, then you can create it.



    ------------------------------
    Brian Gregor
    Global Black Belt
    Microsoft
    Huntersville NC
    7046891564
    ------------------------------



  • 3.  RE: update list item, or create new item if it doesn't exist

    Posted Sep 21, 2018 10:20 AM
    ​Thanks Brian for the advice - I was playing with that yesterday... the problem I'm having is to be able to reference the unique value in List 2.  I'm trying to basically filter for, "if Unique value in List 1 equals Unique value in List 2"

    I can pull up the List 1 reference from the Dynamic content area, but maybe since I haven't actually 'gotten' the items from List 2, those aren't available to select from the Dynamic content?

    would I just have to manually type in what I'm trying to compare in List 2?

    ------------------------------
    Adam Cain
    eLearning Manager
    Granite Bay CA
    9162769608
    ------------------------------



  • 4.  RE: update list item, or create new item if it doesn't exist

    Posted Sep 21, 2018 12:02 PM
    Hi Adam,

    Just saw Brian's answer and your reply to it. Not sure I totally understand the question, but I'm thinking you would use an Apply for Each after the Get Items on the 2nd list, and use the Value returned from that Get Items, even though there would at most be 1 item in the returned array. So the Filter Query (right in the Get Items box) on the second Get Items would be something like: HealthStream eq 'dynamic value from first Get Items value'

    But of course, you would want to first check if the Get Items on list 2 returned anything so you can create a new record if it didn't.

    Hope this helps.

    Dave

    ------------------------------
    David Hock
    9195447040
    ------------------------------



  • 5.  RE: update list item, or create new item if it doesn't exist

    Microsoft Power Platform Team
    Posted Sep 24, 2018 06:38 AM
    exactly David...  take the results of list1 and run through an Apply to Each where you then call GetItems with the filter checking the field in List2 to see if it matches the field from List1 and if you get 0 results, then create a new item; otherwise do whatever is needed if the item exists in List2.



    ------------------------------
    Brian Gregor
    Global Black Belt
    Microsoft
    Huntersville NC
    7046891564
    ------------------------------



  • 6.  RE: update list item, or create new item if it doesn't exist

    Posted Sep 25, 2018 04:35 PM
    thumbnail image

    ​Thanks David an Brian - I get the concept - just can't seem to enter a filter that works - keep getting a 400 / not valid message.  Maybe I'm just off base on how I'm trying to write the comparison.

    I first retrieved the items from List 2 so that I can call up the associated column.  Then I'm performing a 'Get Items, utilizing the Filter Query.  I'm trying to filter so that I only get a match from the value of a field in List 1 called 'HealthStream...', when the value matches the field called 'HealthStream...' in List 2 (they happened to be named the same in each List)



    ------------------------------
    Adam Cain
    eLearning Manager
    Granite Bay CA
    9162769608
    ------------------------------



  • 7.  RE: update list item, or create new item if it doesn't exist

    Posted Sep 25, 2018 05:22 PM
    ​I seem to be having better luck with the following filter - so I think I'm good now!

    thumbnail image


    ------------------------------
    Adam Cain
    eLearning Manager
    Granite Bay CA
    9162769608
    ------------------------------



  • 8.  RE: update list item, or create new item if it doesn't exist

    Microsoft Power Platform Team
    Posted Sep 26, 2018 06:46 AM
    Glad to hear you are making progress!  That's what these community forums are for... :)


    ------------------------------
    Brian Gregor
    Global Black Belt
    Microsoft
    Huntersville NC
    7046891564
    ------------------------------