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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Check if a record alre...
Power Apps
Answered

Check if a record already exists

(0) ShareShare
ReportReport
Posted on by 211

Hi to all,

I have a gallery with checkboxes in every row, I have a selectedRow collection.
Outside the gallery I have a button, I want to Patch the record in my list if the record don't exist or modify the specific record, I'm trying to use this code

ForAll(
 selectedRow;
 If(
 IsBlank(LookUp(IDShadowList; IDshadow = ID));
 Patch(
 SPlist;
 {
 Title: ThisRecord.title;
 IDshadow: ThisRecord.ID
 }
 );
 Notify("Record already exists"; NotificationType.Error)
 )
)

 

it don't work, how can I modify it?

Categories:
I have the same question (0)
  • Ethan_009 Profile Picture
    4,838 Moderator on at

    Hi @common_user ,

     

    You can try the following code:

    ForAll(
     selectedRow;
     With(
     {
     CurrentRecord: LookUp(IDShadowList; IDshadow = ThisRecord.ID; ThisRecord)
     },
     If(
     IsBlank(CurrentRecord);
     Patch(
     SPlist;
     Defaults(SPlist);
     {
     Title: CurrentRecord[@title];
     IDshadow: CurrentRecord[@ID]
     }
     );
     ,
     Patch(
     SPlist;
     CurrentRecord;
     {
     Title: CurrentRecord[@title];
     IDshadow: CurrentRecord[@ID]
     }
     );
     )
     )
    )

     

    Does this help?

  • timl Profile Picture
    36,774 Super User 2026 Season 1 on at

    @common_user 

    You're missing a call to Defaults in the section where you're adding a new record.

    ForAll(
     selectedRow;
     If(
     IsBlank(LookUp(IDShadowList; IDshadow = ID));
     Patch(
     SPlist;
     Defaults(SPlist);
     {
     Title: ThisRecord.title;
     IDshadow: ThisRecord.ID
     }
     );
     Notify("Record already exists"; NotificationType.Error)
     )
    )

     

    This is how you'd adapt the formula to modify an existing record.

    ForAll(
     selectedRow;
     If(
     IsBlank(LookUp(IDShadowList; IDshadow = ID));
     Patch(
     SPlist;
     Defaults(SPlist);
     {
     Title: ThisRecord.title;
     IDshadow: ThisRecord.ID
     }
     );
     Notify("Record already exists"; NotificationType.Error);;
     Patch(
     SPlist;
     LookUp(IDShadowList; IDshadow = ID);
     {
     Title: ThisRecord.title
     }
     )
     )
    )
  • common_user Profile Picture
    211 on at

    Thank you @Ethan_R@timl.

     

    @Ethan_R your code don't work because I can't use ThisItem, my button is outside gallery.

    @timl I tryied something as like your code but I have this error

    Fetching items failed. Possible invalid string in filter query.  Create collection based on the column values in a sharepoint list

     

    in the LookUp function, do you have an idea?

  • common_user Profile Picture
    211 on at

    @WarrenBelz can you help me please

  • WarrenBelz Profile Picture
    154,799 Most Valuable Professional on at

    @common_user ,

    You already have two highly knowledgeable people helping you - please look at their advice.

  • common_user Profile Picture
    211 on at

    I don't have the previous problem. I use the follow code:

    ForAll(
     selectedRow;
     If(
     CountIf(
     SPList;
     IDshadow = LookUp(selectedRow; IDshadow = ID).ID
     ) > 0;
     Patch(
     SPList;
     LookUp(SPList; IDshadow = LookUp(selectedRow; IDshadow = ID).ID);
     {
     Scelta: "DELETE"
     }
     );
     Patch(
     SPList;
     Defaults(SPList);
     {
     Title: ThisRecord.Title;
    
     Choice: "DELETE";
    
     }
     )
     )
    )

     

    so it work but I have a little problem on the true if value. If I have a record that already exists, If I selected 3 already exists rows, my code change only first row.
    How can I change this?

     

    Thank you all

  • Verified answer
    timl Profile Picture
    36,774 Super User 2026 Season 1 on at

    @common_user 

    You can update multiple rows by calling UpdateIf

    ForAll(
     selectedRow;
     If(
     CountIf(
     SPList;
     IDshadow = LookUp(selectedRow; IDshadow = ID).ID
     ) > 0;
     UpdateIf(
     SPList;
     IDshadow = ID;
     {
     Scelta: "DELETE"
     }
     );
     Patch(
     SPList;
     Defaults(SPList);
     {
     Title: ThisRecord.Title;
    
     Choice: "DELETE";
    
     }
     )
     )
    )
  • common_user Profile Picture
    211 on at

    Hi @timl, it works correctly!

    I changed the condition in UpdateIf because with your code it don't find any ID.

    ForAll(
     selectedRow;
     If(
     CountIf(
     SPList;
     IDshadow = LookUp(selectedRow; IDshadow = ID).ID
     ) > 0;
     UpdateIf(
     SPList;
     IDshadow = LookUp(selectedRow; IDshadow = ID).ID;
     {
     Choice: "DELETE";
     }
     );
     Patch(
     SPList;
     Defaults(SPList);
     {
     Title: ThisRecord.Title;
     Choice: "DELETE";
    
     }
     )
     )
    )

     

    with the new condition it works and change the already exists record.

    Are you agree?
    Thank you for your support

  • common_user Profile Picture
    211 on at

    @timl I have last question.
    Do you know if it is possible to use a not delegable function to replace countIf?

    Thank you

  • timl Profile Picture
    36,774 Super User 2026 Season 1 on at

    Hi @common_user 

    The syntax that you posted is valid. Since I'm still not certain as to the columns in IDShadowList and the columns in the Items property of the gallery, if it produces the correct result, I'd be pretty confident that it's correct.

    In terms of CountIf, the following modification should make this section delegable.

     CountRows(Filter(
     SPList;
     IDshadow = LookUp(selectedRow; IDshadow = ID).ID
     )) > 0

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard