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

Not possible to Set or UpdateContext to established variables from inside a DataCard in a Form Control?

I have a pretty simple (I think) use case.

 

I want to show the user a different Edit Form on the same screen depending on a context variable, LogMode.

 

If LogMode="log", show Form1

If LogMode="mileage", show Form2

If LogMode="codes", show Form3

 

I can do this pretty easily with 3 buttons on the Screen with OnSelect=UpdateContext({LogMode:"whatever"}) and my forms appear or disappear as expected. Good! So I have a safety net.

 

BUT my preference would be to do this without buttons! It would be nice if the first DataCard of each form had a drop-down (pulling options from Dynamics365 Option Set), and the user's selection would UpdateContext({LogMode:"whatever"}) and make the proper form appear without thinking about it.

 

So I tried setting the OnChange property of the first DataCard of each Edit Form to something like:

 

If(DataCardValue12.Selected.Value="Travel",UpdateContext({LogMode:"mileage"}),if(DataCardValue12.Selected.Value="No Session",UpdateContext({LogMode:"codes"}),UpdateContext({LogMode:"log"})))

 

This code produced no errors, but it would not work! I kept a test label on the Screen showing me the current LogMode and it refused to change.

 

I also tried using a global variable instead but no difference in behavior.

 

So here's my main question: are Form controls "sandboxed" in some way so that they can't affect variables established outside of themselves? I see people in these threads seem to use variable declarations inside Form controls all the time, so I don't know what I'm doing wrong.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Not possible to Set or UpdateContext to established variables from inside a DataCard in a Form Control?

Hi @jzcase ,

Do you create three separated Edit forms (Form1, Form2 and Form3) within your app, and want to display them based on the LogMode variable?

 

Based on the formula that you provided, I think there is something wrong with it. The DataCardValue12 could only represents the first Combo Box/Dropdown Data card within a single one Edit form, rather than that within each Edit form.

 

Based on the needs that you mentioned, I have made a test, if you want to display/hide your Edit forms based on the variable set up within your Edit form, I afraid that there is no way to achieve your needs in PowerApps currently.

 

As an alternative solution, you could consider add a Dropdown control (or ComboBox) outside the Edit form (within the screen) to achieve your needs. I have made a test on my side, please take a try with the following workaround:

Add a Dropdown control (Dropdown1) within your Edit screen, set the Items property to following:

["log", "mileage", "codes"]

Set the Visible property of the Form1 to following:

If(Dropdown1.Selected.Value = "log", true, false)

Set the Visible property of the Form2 to following:

If(Dropdown1.Selected.Value = "mileage", true, false)

Set the Visible property of the Form3 to following:

If(Dropdown1.Selected.Value = "codes", true, false)

Please take a try with above alternative solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 REPLIES 4
Community Support Team
Community Support Team

Re: Not possible to Set or UpdateContext to established variables from inside a DataCard in a Form Control?

Hi @jzcase ,

Do you create three separated Edit forms (Form1, Form2 and Form3) within your app, and want to display them based on the LogMode variable?

 

Based on the formula that you provided, I think there is something wrong with it. The DataCardValue12 could only represents the first Combo Box/Dropdown Data card within a single one Edit form, rather than that within each Edit form.

 

Based on the needs that you mentioned, I have made a test, if you want to display/hide your Edit forms based on the variable set up within your Edit form, I afraid that there is no way to achieve your needs in PowerApps currently.

 

As an alternative solution, you could consider add a Dropdown control (or ComboBox) outside the Edit form (within the screen) to achieve your needs. I have made a test on my side, please take a try with the following workaround:

Add a Dropdown control (Dropdown1) within your Edit screen, set the Items property to following:

["log", "mileage", "codes"]

Set the Visible property of the Form1 to following:

If(Dropdown1.Selected.Value = "log", true, false)

Set the Visible property of the Form2 to following:

If(Dropdown1.Selected.Value = "mileage", true, false)

Set the Visible property of the Form3 to following:

If(Dropdown1.Selected.Value = "codes", true, false)

Please take a try with above alternative solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
jzcase
Level: Powered On

Re: Not possible to Set or UpdateContext to established variables from inside a DataCard in a Form Control?

You're right: "DataCardValue12 could only represents the first Combo Box/Dropdown Data card within a single one Edit form, rather than that within each Edit form."

 

I have already implemented a similar solution to what you describe using buttons.

 

I hoped I could get past that limitation by having DataCardValue12.OnChange = if(DataVardValue12.Selected.Value="Travel",UpdateContext({LogMode:"mileage"}))

 

I take it from your response that I can't do that. Which is fine, I have an alternate solution.

 

But for my knowledge, could someone explain (or point me to an article that explains) why I can't use a Combo Box in each of my 3 forms to update a context variable that toggles their visibility?

Community Support Team
Community Support Team

Re: Not possible to Set or UpdateContext to established variables from inside a DataCard in a Form Control?

Hi @jzcase ,

Just an update -- you could consider take a try to set up this variable in the OnChange property of first ComboBox Data card in each of your three Edit forms.

 

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

Set the OnChange property of the first ComboBox Data card (ComboBox1) in your Form1 to following:

If(
  ComboBox1.Selected.Value = "log", 
  Set(LogMode, "log"), 
  ComboBox1.Selected.Value = "mileage",
  Set(LogMode, "mileage"),
  ComboBox1.Selected.Value = "codes",
  Set(LogMode, "codes")
)

Set the Visible property of the Form1 to following:

If(LogMode = "log", true, false)

 

Set the OnChange property of the first ComboBox Data card (ComboBox2) in your Form2 to following:

If(
  ComboBox2.Selected.Value = "log", 
  Set(LogMode, "log"), 
  ComboBox2.Selected.Value = "mileage",
  Set(LogMode, "mileage"),
  ComboBox2.Selected.Value = "codes",
  Set(LogMode, "codes")
)

Set the Visible property of the Form2 to following:

If(LogMode = "mileage", true, false)

 

Set the OnChange property of the first ComboBox Data card (ComboBox3) in your Form3 to following:

If(
  ComboBox3.Selected.Value = "log", 
  Set(LogMode, "log"), 
  ComboBox3.Selected.Value = "mileage",
  Set(LogMode, "mileage"),
  ComboBox3.Selected.Value = "codes",
  Set(LogMode, "codes")
)

Set the Visible property of the Form3 to following:

If(LogMode = "codes", true, false)

 

In addition, when you load your Edit form, set one of your three Edit forms as the Default display form. Please take a try with the following workaround:

Set the OnVisible property of the Edit screen to following:

Set(LogMode, "log")

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Community Support Team
Community Support Team

Re: Not possible to Set or UpdateContext to established variables from inside a DataCard in a Form Control?

Hi @jzcase ,

Have you solved your problem?

 

If you have solved your problem, please go ahead to click "Accept as Solution" to identify this thread has been solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 355 members 4,527 guests
Please welcome our newest community members: