SOLVED

How to update a data card field value from an action

%3CLINGO-SUB%20id%3D%22lingo-sub-172660%22%20slang%3D%22en-US%22%3EHow%20to%20update%20a%20data%20card%20field%20value%20from%20an%20action%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-172660%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20been%20playing%20around%20with%20PowerApps%20a%20bit%20more%20with%20the%20SharePoint%20integration.%26nbsp%3B%20It's%20fairly%20straight%20forward%20to%20update%20a%20regular%20text%20field%20from%20a%20button%20by%20setting%20the%20default%20value%20of%20the%20text%20input%20field%20using%20UpdateContext.%20However%2C%20it%20doesn't%20seem%20to%20be%20that%20easy%20with%20a%20data%20card%20value%20because%20the%20text%20field%20(while%20editable)%20is%20pulling%20it's%20data%20from%20the%20list%20item.%26nbsp%3B%20How%20can%20I%20update%20the%20text%20field%20component%20of%20the%20data%20card%20from%20a%20button%20so%20that%20when%20the%20form%20is%20updated%20it%20sends%20the%20new%20data%20to%20the%20list%20item%20as%20if%20I%20typed%20it%20myself.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20example%2C%20say%20I%20have%20a%20button%20called%20%22Blank%20The%20Field%22.%26nbsp%3B%20I%20have%20a%20data%20card%20that%20points%20to%20a%20list%20item%20called%20Notes.%26nbsp%3B%20When%20I%20edit%20the%20form%20I%20can%20delete%20any%20text%20from%20the%20Notes%20field%20and%20update%20the%20list%20item%20by%20saving.%26nbsp%3B%20What%20I%20want%20to%20do%20is%20have%20%22Blank%20The%20Field%22%20do%20that%20for%20me.%26nbsp%3B%20Is%20this%20possible%20from%20a%20button%3F%26nbsp%3B%20Is%20it%20similar%20to%20a%20regular%20text%20box%20and%20I%20am%20just%20missing%20something%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%20in%20advance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-172660%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerApps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-172806%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20update%20a%20data%20card%20field%20value%20from%20an%20action%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-172806%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20after%20some%20testing%2C%20I%20found%20that%20you%20have%20to%20set%20the%20data%20card%20value%20to%20a%20context%20value.%20But%20you%20have%20to%20be%20careful%20because%20the%20context%20value%20should%20be%20set%20when%20the%20form%20is%20visible%20from%20the%20source%20or%20else%20you%20run%20the%20risk%20of%20accidentally%20setting%20bad%20data.%20So%20basically%20it%20goes%20like%20this%3A%3CBR%20%2F%3E-%20set%20Data%20Card%20Value%20default%20property%20to%20a%20contextValue%3CBR%20%2F%3E-%20Set%20the%20contextValue%20to%20the%20source%20of%20that%20field%20on%20screen%20visible%3CBR%20%2F%3E-%20in%20your%20button%20call%20UpdateContext%20and%20set%20the%20contextValue%20to%20whatever%20you%20want%3C%2FP%3E%0A%3CP%3EThis%20sets%20the%20value.%20I'll%20be%20blogging%20it%20with%20a%20bit%20more%20information%20shortly.%20Stay%20tuned.%3C%2FP%3E%3C%2FLINGO-BODY%3E
MVP

I have been playing around with PowerApps a bit more with the SharePoint integration.  It's fairly straight forward to update a regular text field from a button by setting the default value of the text input field using UpdateContext. However, it doesn't seem to be that easy with a data card value because the text field (while editable) is pulling it's data from the list item.  How can I update the text field component of the data card from a button so that when the form is updated it sends the new data to the list item as if I typed it myself.

 

For example, say I have a button called "Blank The Field".  I have a data card that points to a list item called Notes.  When I edit the form I can delete any text from the Notes field and update the list item by saving.  What I want to do is have "Blank The Field" do that for me.  Is this possible from a button?  Is it similar to a regular text box and I am just missing something?

 

Thanks in advance.

1 Reply
best response confirmed by David Drever (MVP)
Solution

So after some testing, I found that you have to set the data card value to a context value. But you have to be careful because the context value should be set when the form is visible from the source or else you run the risk of accidentally setting bad data. So basically it goes like this:
- set Data Card Value default property to a contextValue
- Set the contextValue to the source of that field on screen visible
- in your button call UpdateContext and set the contextValue to whatever you want

This sets the value. I'll be blogging it with a bit more information shortly. Stay tuned.