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 / Setting a field value ...
Power Apps
Unanswered

Setting a field value with click of a button.

(0) ShareShare
ReportReport
Posted on by

I have a phone template app connected to a SharePoint list with a single line of text column called Request Status.  I have a button in the Edit view that is suppose to update the Request Status to "New" when clicked.  The button OnSelect forumal is : UpdateContext({RequestStatusVar: "New"})

 

The Default value of my Request Status field is set to RequestStatusVar.  When I test it out for the first time by creating a new form, I click the button which sets the variable to "New" and Request Status is set to "New" as well.  Then when I click on the Add new Item icon from the Display view, it shows that Request Status is set to "New" before I have even clicked the button for this record. 

 

I do not understand why the variable is set to "New" on the new record.  It seems that variable values carry over to new records?  Why is this the case?  What other code would I need to prevent this?

Categories:
I have the same question (0)
  • Srautio Profile Picture
    60 on at

    Unless you are Updating the variable anywhere else in the context you are using it, it will remain whatever value you assign it when it was first initialized. In your case the first time you pressed the button.

     

    So unless you Update your variable anywhere else in your form submit process it will keep the value of "New".

     

    So right now you could replace the default value of Request Status field to "New" and it would behave the same way. 

     

    UpdateContext function in Powerapps

     

  • PowerAid Profile Picture
    on at

    @Srautio wrote:

    Unless you are Updating the variable anywhere else in the context you are using it, it will remain whatever value you assign it when it was first initialized. In your case the first time you pressed the button.

     

    So unless you Update your variable anywhere else in your form submit process it will keep the value of "New".

     

    So right now you could replace the default value of Request Status field to "New" and it would behave the same way. 

     

    UpdateContext function in Powerapps

     


    Thanks for the link.  I need some clarification on this info:

     

    "A context variable holds its value until the app is closed. If you define a context variable and set its value on a particular screen, that information remains intact even if the user switches to a different screen. Once the app is closed, the context variable's value will be lost and must be recreated when the app is loaded again."

     

    So is this saying that unless the PowerApp is closed the current value will still hold?  So as long as the app is open, the value will get passed to other records that you open (in the correspondning screen)?

  • Srautio Profile Picture
    60 on at

    So is this saying that unless the PowerApp is closed the current value will still hold?  So as long as the app is open, the value will get passed to other records that you open (in the correspondning screen)?

     

    Yes that is how it should work.

     

    What was it you were trying to do with your variable?

  • PowerAid Profile Picture
    on at

    @Srautio wrote:

    What was it you were trying to do with your variable?


    I am experimenting on how I can set the Request status field with a click of a Button for a particular record. I do not want the value past on to another record and I do not want the value to be lost in the original record. 

     

    I have a lot of experience with Infopath and so I am used to values being "pushed".  I know PowerApps values are "pulled". I am trying to wrap my head around these different concepts in PowerApps like variables.

  • Srautio Profile Picture
    60 on at

    @PowerAid wrote:


    I am experimenting on how I can set the Request status field with a click of a Button for a particular record. I do not want the value past on to another record and I do not want the value to be lost in the original record. 


    Well if you want to clear your ContextVariable in between submissions you could add the following

    UpdateContext({RequestStatusVar: ""})

    to either the New Record Screens onVisible property or directly on the Submit button OnSelect property.

     

    However variables are not tied to a record, ContextVariables are screenSpecific and GlobalVariables 

    Set(variableName, Value)

    are accessible all throughout the app.

     

    Also you can pass variables in between screens as a third optional value in the Navigate() function.

    Navigate(Screen, Cover, {var: "variable"})

    Navigate()

     

    You can allso use ContextVariables as "toggle-able" booleans by setting the onSelect property of say a button to:

    UpdateContext({variable: !variable})

    Whenever you click said button it will swap to the opposite value. It defaults to false. I use this alot to hide UI elements from the user untill they click a button by having the UI elements' Visible property set to: variable.

  • v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @PowerAid,

    Do you want the RequestStatusVar value not to be passed to another record, and not to be lost in previous record?

    I agree with @Srautio's thought almost, the Context variable (created via UpdateContext function) is scoped to a screen, which means that you can't build a formula that refers to a context variable on another screen. If you don't close your app or change its value, it would remain its previous value continuously.

    I have made a test on my side, please take a try with the following workaround:10.JPG

     

    11.JPG

    Set the OnVisible property of your Edit screen (on your side, it is Edit view) to following formula:

    UpdateContext({RequestStatusVar:Blank()}) /* Initialize the RequestStatusVar variable when you create a new form */

    Set the OnSelect property of the "Update" button to following formula:

    UpdateContext({RequestStatusVar: "New"}) /* Update the RequestStatusVar variable when you click the button */

    Set the Default property of the TextInput control within the Request Status Data card to following:

    If(
     EditForm1.Mode=FormMode.New,
     RequestStatusVar,
     Parent.Default
    )

    Or 

    Set the Default property of the Request Status Data card to following:

    If(
     EditForm1.Mode=FormMode.New,
     RequestStatusVar,
     ThisItem.Request_x0020_Status
    )

    The GIF screenshot as below:Test1.gif

     

    Best regards,

    Kris

  • kotlonarendra Profile Picture
    3 on at

    Hello,
    I tried the above solution, it works only when i create new entries, but for updating existing entries no action is taken when button is clicked.

    kotlonarendra_0-1609424181574.png

     

    kotlonarendra_1-1609424343128.png

     

     

    Could you please let me know, if i am doing any step wrong.

     

    --

    Thanks,

    Naren

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 914

#2
11manish Profile Picture

11manish 617

#3
Valantis Profile Picture

Valantis 598

Last 30 days Overall leaderboard