I have a Powerapps form connected to a SharePoint list that includes a single Choice column called Status. When someone attempts to change the status to "Confirmed to Discard" or "Discarded", I want a pop-up to become visible, asking them to confirm if they can discard the samples. I have created a pop-up of sorts within the Status datacard by grouping a rectangle with a label and two buttons. I have set the Group1.Visible to If("Discard" in DataCardValue51.Selected.Value,true). This works as expected.
What I would like to have happen is...
- If the person clicks the NO button, I want the pop-up to close and put the Status choice to what it was before they tried one of the options with "Discard".
- If they click the YES button, I want the pop-up to close and accept their change.
So the button needs to conditionally override the visibility when YES is selected, otherwise the pop-up remains visible because "Discard" is in the selected value. I think I need to set some sort of variable for the visibility, but I'm new to PowerApps and don't know how to do this. Any advice would be appreciated!
Solved! Go to Solution.
Well, basically there are a few things to do, for example, what type of variable is best to use for your case, global or context variable.
Anyway, in my example I use global variable, if it doesn't work for your case, let me know.
Therefore, in the OnStart property of the App I defined the following variables:
/*
The gblReset variable is for resetting the option control to its original state, ie, no choice. Strangely, variables that are used to reset a control, Power Apps doesn't seem to take it well, that's why I set the variable first to false and then to true, as the initial state of the control is unselected.
*/
Set(gblReset, false);
Set(gblReset, true);
// The gblShowPopUp variable is for defining whether the popup is visible or not.
Set(gblShowPopUp, false);
In the Reset property of the selection control, place the gblReset variable:
In the OnSelect property of the selection control, set the gblShowPopUp variable to true:
From there, in your popup, set the Visible property to the gblShowPopUp variable:
In the OnSelect property of the NO button, set:
Notice that we defined the variables again...
On the Yes button, in the OnSelect property, proceed with what your App should do...
Final result:
Hi! I hope I was helpfull. Please always mark the answer that helped you, so others who need it will find it faster.
This is on me, as I may not have been clear in my initial post; I'd like the pop-up to appear only if the selected option is "Discarded" or "Confirmed to Discard" (i.e. contains "Discard"). There are many other choices, such as "Processing" and "Analyzing", where I don't need a confirmation pop-up.
Well, in this case you can use a Switch function (in the option's OnSelect property) to test if the selected value contains a word necessary for the popup to appear, or even use the IF function with OR. It would be more or less like this:
Choice.OnSelect:
// using switch function
Switch(
Self.Selected.Value,
"Selected Value 1",
Set(gblShowPopUp, true),
"Selected Value 2", "does nothing",
// and so on
)
// using IF with OR function
If(
Or(
Self.Selected.Value = "Selected value 1",
Self.Selected.Value = "Selected value 3"
),
Set(gblShowPopUp, true),
"does nothing"
)
As for the last step, where you indicate I should proceed with code telling my App what it should do, all I need it do when "Yes" is selected, is to accept the change, which it appears to do. Does this mean no additional code is needed for the Yes button's OnSelect property?
Correct, no additional code is needed in this case.
Hi! I hope I was helpfull. Please always mark the answer that helped you, so others who need it will find it faster.
Well, basically there are a few things to do, for example, what type of variable is best to use for your case, global or context variable.
Anyway, in my example I use global variable, if it doesn't work for your case, let me know.
Therefore, in the OnStart property of the App I defined the following variables:
/*
The gblReset variable is for resetting the option control to its original state, ie, no choice. Strangely, variables that are used to reset a control, Power Apps doesn't seem to take it well, that's why I set the variable first to false and then to true, as the initial state of the control is unselected.
*/
Set(gblReset, false);
Set(gblReset, true);
// The gblShowPopUp variable is for defining whether the popup is visible or not.
Set(gblShowPopUp, false);
In the Reset property of the selection control, place the gblReset variable:
In the OnSelect property of the selection control, set the gblShowPopUp variable to true:
From there, in your popup, set the Visible property to the gblShowPopUp variable:
In the OnSelect property of the NO button, set:
Notice that we defined the variables again...
On the Yes button, in the OnSelect property, proceed with what your App should do...
Final result:
Hi! I hope I was helpfull. Please always mark the answer that helped you, so others who need it will find it faster.
Your instructions are excellent, and I was able to replicate what you did. Thank you!
This is on me, as I may not have been clear in my initial post; I'd like the pop-up to appear only if the selected option is "Discarded" or "Confirmed to Discard" (i.e. contains "Discard"). There are many other choices, such as "Processing" and "Analyzing", where I don't need a confirmation pop-up.
As for the last step, where you indicate I should proceed with code telling my App what it should do, all I need it do when "Yes" is selected, is to accept the change, which it appears to do. Does this mean no additional code is needed for the Yes button's OnSelect property?
This is on me, as I may not have been clear in my initial post; I'd like the pop-up to appear only if the selected option is "Discarded" or "Confirmed to Discard" (i.e. contains "Discard"). There are many other choices, such as "Processing" and "Analyzing", where I don't need a confirmation pop-up.
Well, in this case you can use a Switch function (in the option's OnSelect property) to test if the selected value contains a word necessary for the popup to appear, or even use the IF function with OR. It would be more or less like this:
Choice.OnSelect:
// using switch function
Switch(
Self.Selected.Value,
"Selected Value 1",
Set(gblShowPopUp, true),
"Selected Value 2", "does nothing",
// and so on
)
// using IF with OR function
If(
Or(
Self.Selected.Value = "Selected value 1",
Self.Selected.Value = "Selected value 3"
),
Set(gblShowPopUp, true),
"does nothing"
)
As for the last step, where you indicate I should proceed with code telling my App what it should do, all I need it do when "Yes" is selected, is to accept the change, which it appears to do. Does this mean no additional code is needed for the Yes button's OnSelect property?
Correct, no additional code is needed in this case.
Hi! I hope I was helpfull. Please always mark the answer that helped you, so others who need it will find it faster.
This works exactly as needed. Thank you so much!
User | Count |
---|---|
253 | |
113 | |
92 | |
48 | |
38 |