web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / For All Patch to two d...
Power Apps
Answered

For All Patch to two different sharepoint lists

(0) ShareShare
ReportReport
Posted on by 315

Hi,

 

I have two Different sharepoint lists(List A and List B). I need to patch records which are in List A to List B. Before patching each record from list A to list B, i need to check the record which is going to be patached from List A exists or not in List B. If record exists then update the record, else create new record.

 

Appreciate your help!

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,989 Moderator on at

    @kbilakanti 

    Lets assume that every record in list A has a unique ID that gets transferred into List B.


    List A: ID

    ListB:  IdFromListA

     

    Here's my idea:

     

     

    ForAll(
     ListA,
     If(IsBlank(Lookup(ListB, ListB[@IDFromListA] = ListA[@ID])),
     Patch(
     ListB,
     Defaults(ListB),
     {Field1: ListA[@Field1]}
     ),
     Patch(
     ListB,
     Lookup(ListB, ListB[@IDFromListA] = ListA[@ID]),
     {Field1: ListA[@Field1]}
     )
     )
    )

     

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • kbilakanti Profile Picture
    315 on at

    @mdevaney  In this case please see my comments below.

    Set(editRecord, Lookup(ListB, ListB[@IDFromListA] = ListA[@ID])); ---> It only get's one record id but i need all record id's
    ForAll(
     ListA,
     If(IsBlank(editRecord),
     Patch(
     ListB,
     Defaults(ListB),
     {Field1: ListA[@Field1]}
     ),
     Patch(
     ListB,
     editRecord,
     {Field1: ListA[@Field1]}
     )
     )
    )
  • mdevaney Profile Picture
    29,989 Moderator on at

    @kbilakanti 

    I was being too "fancy".  Please see my revision in the original post.

  • kbilakanti Profile Picture
    315 on at

    @mdevaney  Thanks, but i found a little thought on top of your solution, Below is my updated solution on top it."editrecord" doesn't exist in this context. so used Filter to get record id if record exist.

     

    ForAll(
     ListA,
     If(IsBlank(Lookup(ListB, ListB[@IDFromListA] = ListA[@ID])),
     Patch(
     ListB,
     Defaults(ListB),
     {Field1: ListA[@Field1]}
     ),
     Patch(
     ListB,
     editRecord,- Instead of editRecord i used -> First(Filter(ListB, ListB[@IDFromListA] = ListA[@ID]))
     {Field1: ListA[@Field1]}
     )
     )
    )

     

  • Verified answer
    mdevaney Profile Picture
    29,989 Moderator on at

    @kbilakanti 

    That's great!  I would suggest using LOOKUP instead of FIRST + FILTER though because of the impact to performance.  FIRST + FILTER is slower because it has to retrieve the whole result set then get the first record.  LOOKUP simply stops the process once the record is found 🙂

     

    ForAll(
     ListA,
     If(IsBlank(Lookup(ListB, ListB[@IDFromListA] = ListA[@ID])),
     Patch(
     ListB,
     Defaults(ListB),
     {Field1: ListA[@Field1]}
     ),
     Patch(
     ListB,
     Lookup(ListB, ListB[@IDFromListA] = ListA[@ID]),
     {Field1: ListA[@Field1]}
     )
     )
    )

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • kbilakanti Profile Picture
    315 on at

    @mdevaney  Patch is working fine if  the if condition is true(blank), in else patch is not updating the existing record. any thoughts on that? 

  • mdevaney Profile Picture
    29,989 Moderator on at

    @kbilakanti 

    I think the issue would be with the argument highlighted in blue below.  Patch will try to update the field but will leave it the same if it gets an unexpected value (example: wrong format, wrong type, etc.).

     

    What Column Type in SharePoint are you trying to Patch?  Can you please let me know and share the exact code you are using 🙂

     

    ---

     

    ForAll(
        ListA,
        If(IsBlank(Lookup(ListB, ListB[@IDFromListA] = ListA[@ID])),
            Patch(
                ListB,
                Defaults(ListB),
                {Field1: ListA[@Field1]}
            ),
            Patch(
               ListB,
                Lookup(ListB, ListB[@IDFromListA] = ListA[@ID]),
                {Field1: ListA[@Field1]}
           )
       )
    )

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard