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 / Set DataCardValue from...
Power Apps
Answered

Set DataCardValue from Gallery selection

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello, So i'm looking for guidance on how to set a datacardvalue based on a selection from a gallery.

 

Currently I have an edit form that has a "Customer" field - DataCardValue2. The default is set to "ThisItem.Customer2"  which works properly setting the the text to my customer value from a Sharepoint List. Keep in mind this value could be blank

 

Next to the form I have a gallery called Gallery2 that is populated by an excel spreadsheet filled with customer information. I filter this gallery based on a text field.  

 

What I want to do is the following

1) Load the form, if there is a customer value in the SP List, populate DatavalueCard2

2) If the DatavalueCard2 field is blank I want to give the end user the ability to lookup the customer in the gallery, select the appropriate customer and then take that value and update the DatavalueCard2 field.

3) Also, if the DatavalueCard2 is populated already, the end user can still lookup a customer, select it and override existing value in event they made a mistake. 

 

From what I have read I need to use set a variable and then use Updatecontext. I have tried this but I'm running into issue with my If logic I think. Looking for some help on best practice and how to code this.

 

PowerAppScreenShot.JPG

 

Thanks

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,526 Most Valuable Professional on at

    Hi @Studz02 ,

    There are a couple of ways of doing this, but I will stick with the Variable concept you mention.

    On the OnSelect of the gallery, put this

    UpdateContext({vCustomer:ThisItem.Customer});
    Reset(YourFormCustomerControl)

     On the Default of the customer control in your form

    If(
     !IsBlank(vCustomer),
     vCustomer,
     Parent.Default
    )

    Then in the Save code add this

    UpdateContext({vCustomer:Blank()})

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

     

  • Jon Studsrud Profile Picture
    Microsoft Employee on at

    Thank you. This worked out great. Just curious, is this the best approach? or would you have gone a different route?

  • WarrenBelz Profile Picture
    156,526 Most Valuable Professional on at

    Thanks @Studz02 ,

    You can use the code directly in the Default of the control and reset it, but a Variable is probably cleaner.

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
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard