Forum Discussion

Deleted's avatar
Deleted
Dec 11, 2017

How to Update a Field through a button's OnSelect Event

I've watched quite a few PowerApps videos this weekend and feel I have enough knowledge to try my hand at customizing some forms this coming week. However, something very basic escapes me and I didn't see it addressed in the vids I have watched thus far. 

In InfoPath or visual basic like environments I have used in the past (e.g. Access modules), it was easy to update a field via a button push event (or clicking some button-like graphic). Something like...

 

Status.Value = "Complete"

This does not seem as straightforward in PowerApps. In the form below, I want a quick way to mark a task as done, by clicking on a "button". I would probably replace the Status dropdown with a read-only field or label eventually. 

I figured this formula should work, but nope. What am I doing wrong.

 

 

 

 

 

 

 

 

 

  • You would need to set the value of the field you want to change to a variable and then set that variable with the OnSelect event.

     

    Depending if you need this across multiple pages you can use either a local (context) or global variable.

     

    To set a local variable you can use UpdateContext( { ContextVariable1Value1 } ) or like these 2 examples: UpdateContext( { CountNumber: 1 } ) or UpdateContext( { Name: "John"} )

     

    To set a global variable you can use SetVariableNameValue ) or like these 2 examples: Set(  CountNumber, 1  ) or Set( Name, "John" )

     

    To use show either of the above variable types is as easy as putting the variable name in the text property of the object you want to use.

     

    See these pages for more:

    https://docs.microsoft.com/en-us/powerapps/functions/function-updatecontext

    https://docs.microsoft.com/en-us/powerapps/functions/function-set

    • Deleted's avatar
      Deleted
      Hey Peter
      Thanks I will read that tomorrow AM. That would mean, I am assuming that the variable needs to be initialized to the existing value of the status field when the form is loaded.
      I will study it and mark this as the solution once I have it working.
    • Peter McDonald's avatar
      Peter McDonald
      Brass Contributor

      I should mention that if you want to use the variable as the value of an input field you can set the Default property of the field to the variable.

      • Deleted's avatar
        Deleted
        Peter
        Do I set the Default property of the target field (Status) to the variable in runtime programmatically or do I do it in advance as a formula?

        If it’s it advance, then I think I need to capture the field value and put it in the variable on load, so that the field can be populated with that value; then have my button change the variable to the new value (e.g. “Complete”); then the field will reflect the updated value. Is this correct?
    • Pınar Rehber's avatar
      Pınar Rehber
      Copper Contributor

      Hi, 

      How can we change a column value to variable? 

       I have  and dislike columns in my excel. 

       When the user clicks the Like button under the image I want the column value to be increased by 1, same for dislike button. 

      Also for each image if the user clicked Like button she/he shouldnt be able to click dislike button and viceversa. 

      How can I do this? 

       

      Thanks, 

Resources