cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nsexton
Frequent Visitor

Global Variable Reset When Navigating to New Page

Hello,

 

I have a Power App that has a login page that, once the password is correct, take user to a landing page. The password from this page is stored in the function: ;Set(vPassword,PasswordInput); on the Onselect property of the Login button. There are two different passwords that users can use that will allow buttons on the next screen to work or not depending on the password's value. This all works great, but I run into an issue when I try to use this variable on any screen other than the landing page. 

 

The two buttons that I need to work are for adding new records to tables in SharePoint lists and the Onselect property code is ResetForm('GeneralProject Form');ResetForm(PMPForm); ResetForm(ProjectFundingForm);ResetForm(ProjectScheduleScreen);ResetForm(ProjectContractForm);Set(varFormDataP,Defaults('Projects Data')); Navigate('General Project'); 

 

Once I am navigated to the first screen in the sequence, the vPassword variable has no value. I am trying to set the DisplayMode of certain fields on each screen to be Edit or Disabled depending on which password the user input. Is the issue Set(varFormDataP,Defaults('Projects Data'))? How can I ensure that the vPassword variable retains value throughout the App?

 

Thank you in advance! I have been stuck on this for days.

1 ACCEPTED SOLUTION

Accepted Solutions
BCBuizer
Super User
Super User

Hi @nsexton,

 

Are you sure the variable has a value in the initial screen?

 

Looking at the code, there seems to be a part missing. Assuming you are using a text input control for the user to enter their password, I would expect:

 

Set(vPassword,PasswordInput.Text)


Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

View solution in original post

7 REPLIES 7
RandyHayes
Super User
Super User

@nsexton 

If it is a global variable (made by using the Set function) then it will be available through the entire app.

Make sure you have not done an UpdateContext function with the same name on any screen you are using this on as it will interfere with the global.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
TheRobRush
Super User
Super User

A variable you set using Set() will not lose its value, unless you have another line of code firing somewhere that sets it to something else, So I would check everything that runs between point a and point b, including onvisibles and etc the whole lot. Only other exception I could think of is if its in a custom control then those don't always behave same but assuming thats not the issue here since you did not mention creating a custom control..

 

Id recommend going to view, variables, then go down to that variable click on it and see every place it's referenced in code, will help you find where this is occuring

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

I did not mean to create a custom control, but it seems as though I have. All of my dropdowns and input boxes are from the SharePoint list, so when I went to edit it changed the control to custom. Is there something I need to do to change it from custom?

TheRobRush
Super User
Super User

Custom control doesnt mean a control you have customized, youd actually need to go up top and click input custom control.and then edit it outside your app and then drop it in. If thats what you've made, and theres not a reason you meed it that way, I'd recommend just readding a new gallery or labels etc whatever was inside that custom control and copy over the values etc so you get it in the app itself. Custom controls are mostly so you can design things you can drag and drop.into multiple apps, but because they are designed to work across multiple apps getting them working properly is more work than the in app controls

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

Oh okay. I have not done that. Is there anything else I can do? 

BCBuizer
Super User
Super User

Hi @nsexton,

 

Are you sure the variable has a value in the initial screen?

 

Looking at the code, there seems to be a part missing. Assuming you are using a text input control for the user to enter their password, I would expect:

 

Set(vPassword,PasswordInput.Text)


Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.
TheRobRush
Super User
Super User

Oooh yes as @BCBuizer  pointed out leaving .text off that set would make your set blank, haha can't believe I didn't see that

_____________________________________________________________________________________
Like my answer? - Hit that Thumbs Up. Resolved the Issue? - Hit Accept as Solution.
This helps others find solutions to future issues!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,699)