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 / Power App Array Functi...
Power Apps
Unanswered

Power App Array Function leveraging a toggle to make an item as a favorite.

(0) ShareShare
ReportReport
Posted on by 4

First, I would consider myself very new to Power Apps. I have been creating a Power App that is leveraged as a consumer portal to search for reports and datasets owned by my team.  I am using the following code on a toggle (to favorite and unfavorite) to create new / update records in a Sharepoint list.

Patch('User Favorites',Defaults('User Favorites'),{Title:ThisItem.Title,Description:ThisItem.Description,'Report ID':ThisItem.ID,Link:ThisItem.'Analytics Link',Subject:ThisItem.'DataSubject (DataSubject0)',Date:Now(),User:User().FullName,Email:User().Email,Favorite:Toggle1_1.Value})

 

This is currently a new record for each time the toggle is used.  I would like to update so that if a user has already favorited an item and they want to unfavorite it, it will update the sharepoint record vs. creating a new one.  Current Sharepoint fields are ID, Description, Email, Favorite (... true or false based upon toggle), User, Link, Date, Subject.

 

Any help would be appreciated.

Categories:
I have the same question (0)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Most,

     

    We can use the following structure in order to create when no record exists and vice versa for update. I have added inline comments to further explain the code. Should you want to update all fields in case the record exists use the following code:

     

    Patch(
     'User Favorites',
     //Coalesce returns the first value that does not return a blank output
     //Should no record be found for this ID (does not exist) then we will create a new one
     Coalesce( 
     LookUp('User Favorites', 'Report ID' = ThisItem.ID),
     Defaults('User Favorites')
     ),
     {
     Title:ThisItem.Title,
     Description:ThisItem.Description,
     'Report ID':ThisItem.ID,
     Link:ThisItem.'Analytics Link',
     Subject:ThisItem.'DataSubject (DataSubject0)',
     Date:Now(),
     User:User().FullName,
     Email:User().Email,
     Favorite:Toggle1_1.Value
     }
    )

     

    Should you only want to update the Favorite column, use the following instead:

     

    With(
     {wLookUp: LookUp('User Favorites', 'Report ID' = ThisItem.ID)},
     If(
     //Check whether record exists
     IsBlank(wLookUp),
     //If not create a new one
     Patch(
     'User Favorites',
     Defaults('User Favorites'),
     {
     Title:ThisItem.Title,
     Description:ThisItem.Description,
     'Report ID':ThisItem.ID,
     Link:ThisItem.'Analytics Link',
     Subject:ThisItem.'DataSubject (DataSubject0)',
     Date:Now(),
     User:User().FullName,
     Email:User().Email,
     Favorite:Toggle1_1.Value
     }
     ),
     //Else update the Favorite field
     Patch(
     'User Favorites',
     wLookUp,
     {
     Favorite:Toggle1_1.Value
     }
     )
     )
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • LaurensM Profile Picture
    12,516 Moderator on at

    @Most,

     

    The code that I just supplied should be in the OnCheck property of your Toggle. The OnUncheck can simply contain an update - since we'd expect a favorited record to already exist.

    //OnUnCheck
    Patch(
     'User Favorites',
     LookUp('User Favorites', 'Report ID' = ThisItem.ID),
     {
     Favorite:Toggle1_1.Value
     }
    )

    Add additional columns should you want to update columns outside of 'Favorite'. Should Toggle1_1 refer to the Toggle we are currently adjusting - you can also reference the value by using Self.Value instead.

     

    I hope this helps!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard