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 / Update ForeignKey Shar...
Power Apps
Answered

Update ForeignKey Sharepoint List using onSelect button with Patch()

(0) ShareShare
ReportReport
Posted on by 7

My problem is what I describe in the title.

I want to update a foreign key on my sharepoint list with a button.

 

I have two List with OneToMany relation:

User{ ID, Name, Surname}
Book{ID, Title, Author, ID_User}

When I go in one user details, with a gallery,  i can see the book related in another gallery with a Filter:

Filter(Book,BrowseGallery1.Selected.ID = ThisRecord.IDUser.Id)

In this gallery i want to add a Trash and when i click the button remove the Book of this User, soo i want to remove the relation and see only the book related with this user.

 

I try with:

Patch(ThisItem, First( Filter(Book, BrowseGallery1.Selected.ID = ThisRecord.IDAnagrafica.Id)), { ID_User:  0} )

But give me an error. I try this patch with other columns like {Title: "TEST"} and it work.

I try also with {ID_User: Value("Your value")} but nothing.

Can we help?

 

Thx for help

Categories:
  • v-yutliu-msft Profile Picture
    Microsoft Employee on at

    Hi @AldoFra ,

    Do you want to update your lookup field from having value to blank?
    If so, please do not use "0" or Value("Your value") to update lookup field.

    LookUp field  is a special data type, which contains two columns : Id and Value.

    To update this field to blank is quite easy, you just need to use Blank() to update.

    The steps are :

    1)turn on this setting in your app

    (or else you could not update a field from having value to blank value.)

    File->settings->advanced settings

    943.PNG

     

    2)Use formula like this to update:

    Patch(Book, First( Filter(Book, BrowseGallery1.Selected.ID = ThisRecord.IDAnagrafica.Id)), { ID_User: Blank()} )

     

     

    Best regards,

  • AldoFra Profile Picture
    7 on at

    Thanks for the reply and the explanation of LookUp.

    I try with your solution but not work. Give me a Error:

    "The type of this argument 'ID_User' does match the expected type 'Record'. Found type 'Error' "

     

    I think accept only a type 'ID_User' for example another book with the same type of column 'Foreign Key'.

    I found a temporary solution. I create a 'Librarian' book associated with a 'Librarian' User.

    Soo i simplify the forum and  i can assign the book at the 'librarian':

    Patch([@Book], Gallery4.Selected, { ID_User: LookUp(Book, ThisRecord.Title= "Librarian").ID_User})

     

    But it's not possible that i cannot assign a Black() value.

  • Verified answer
    v-yutliu-msft Profile Picture
    Microsoft Employee on at

    Hi @AldoFra ,

    Have you firstly turned this setting on?

    985.PNG

     Only if you turn this setting on, then you could update lookup field with Blank().

    Patch([@Book], Gallery4.Selected, { ID_User: Blank()})

     

     

     

    Best regards,

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard