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 / Check if a record alre...
Power Apps
Unanswered

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,383 Super User 2025 Season 2 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
    153,026 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,383 Super User 2025 Season 2 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,383 Super User 2025 Season 2 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

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 793 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard