cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jdscott
Level: Powered On

Button DisplayMode.Disable to DisplayMode.Edit not working as expected

Hello all,

 

I have a button on my home screen whose OnSelect property sends a report in an email. I want the button to be disabled once pressed to indicate to the user that the report is sent and to keep them from sending multiples. To the OnSelect property of the button I've added:

 

...;UpdateContext({sentreport:true})

The DisplayMode property, then:

 

If(sentreport,Disabled,Edit)

 

I want the button to be selectable again if the user adds information to their report. On another screen (inspection screen), I have an icon which is used to submit a form and then navigate away from the screen. I added the following to the OnSelect property of the icon:

 

UpdateContext({sentreport:false})

I've also tried:

 

Set(sentreport, false)

Neither code results in the button's DisplayMode property resetting to DisplayMode.Edit and being selectable again.

 

I'm not sure if this matters, but the screen which adds to the report (inspection screen) navigates to a selection screen, not the home screen with the button in question. Perhaps my sentreport variable isn't carried over from the inspection screen?

 

Any idea why my code isn't working?

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft Paul_C
Microsoft

Re: Button DisplayMode.Disable to DisplayMode.Edit not working as expected

I'm not sure, but it sounds like you're running into an issue with the scoping of context variables. UpdateContext creates variables that only exist on that screen. If I have an UpdateContext({sentreport: true}) on one screen and an UpdateContext({sentreport: false}) on another screen, than each screen has its own sentreport variable. In other words, there will be two different variables with the same name. You can pass context variables through the Navigate function, though, so you can use the value in another screen.

 

However, I recommend that in your case you just use the Set() function. Set(sentreport, false) will create a global variable that can be used on all screens.

 

You may be wondering why Set() wasn't working in your example. This is because if I have both Set(sentreport, false) and UpdateContext({sentreport: true}), the app has two variables with the same name, again. In this case, though, it is a global variable and a local context variable. In cases like this, screens will use the local variable where it's available and the global variable where it isn't. If you replace all of the UpdateContext's with Set() in your case, you should be fine.

 

One feature you may find useful when trying to figure out these kinds of problems is the variables page.

VariablesPage.png

 

If you want to learn more about variables in PowerApps, here are some links to the documentation:

UpdateContext documentation: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-updatecontext 

Set() documentation: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-set

 

I hope this helps!

 

 

 

 

- Paul C.
Software Engineer on PowerApps

View solution in original post

2 REPLIES 2
Super User
Super User

Re: Button DisplayMode.Disable to DisplayMode.Edit not working as expected

Hi @Jdscott

 

The correct function to use is Set, because the scope of any variables that we define with UpdateContext is limited to the screen.

 

To avoid any ambiguity, you'll need to remove any call to UpdateContext on your main screen that sets the sentreport variable.

 

On the button that sends the report, you would add the formula...

...;Set(sentreport,true)

And on the inspection screen, you would use the formula:

;Set(sentreport,false)

 

Microsoft Paul_C
Microsoft

Re: Button DisplayMode.Disable to DisplayMode.Edit not working as expected

I'm not sure, but it sounds like you're running into an issue with the scoping of context variables. UpdateContext creates variables that only exist on that screen. If I have an UpdateContext({sentreport: true}) on one screen and an UpdateContext({sentreport: false}) on another screen, than each screen has its own sentreport variable. In other words, there will be two different variables with the same name. You can pass context variables through the Navigate function, though, so you can use the value in another screen.

 

However, I recommend that in your case you just use the Set() function. Set(sentreport, false) will create a global variable that can be used on all screens.

 

You may be wondering why Set() wasn't working in your example. This is because if I have both Set(sentreport, false) and UpdateContext({sentreport: true}), the app has two variables with the same name, again. In this case, though, it is a global variable and a local context variable. In cases like this, screens will use the local variable where it's available and the global variable where it isn't. If you replace all of the UpdateContext's with Set() in your case, you should be fine.

 

One feature you may find useful when trying to figure out these kinds of problems is the variables page.

VariablesPage.png

 

If you want to learn more about variables in PowerApps, here are some links to the documentation:

UpdateContext documentation: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-updatecontext 

Set() documentation: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-set

 

I hope this helps!

 

 

 

 

- Paul C.
Software Engineer on PowerApps

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,658)