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

Setting Variable in If statement

Hi All, 

 

Trying to update a variable based on a IF statement 

 

If(IsMatch(VarSeverity, "Catastrophic") , set(VarPriScore, 10))

 

getting the following error "behavior function in a non behavior property. You can't use this property to change values elsewhere in the app"

 

I have 3 drop down boxes that based on the selections a score gets created, but need to set the score to a global variable to pass back to the previous page.  Any help would be appreciated. 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Setting Variable in If statement

Hi @Kevball2 ,

 

Could you tell me which control and property you use the formula to?

 

Please notice, Set function is a behavior formula, you can only use it in the formulas for the OnSelect, OnVisible, OnChange, and other On... properties.

 

To pass the score selected from dropdown, you can set your formula to OnChange property of dropdown.

 

Best regards,

Sik

View solution in original post

4 REPLIES 4
Highlighted
Super User II
Super User II

Re: Setting Variable in If statement

You need to set it an "On" event. So you try moving the formula to the OnChange event of the third drop down. 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
Helper I
Helper I

Re: Setting Variable in If statement

You can use UpdateContext and Navigate function  to achieve this 

Using Update Context and Navigate:

The page where you have all you 3 dropdowns ... for that page set OnVisble formula to UpdateContext({score:0}) --> this basically defining  a local variable .. local to that page

When the score is created or set, use the following formula to make a copy of the newly created set
UpdateContext({ score: If(IsMatch(VarSeverity, "Catastrophic"), 10, -1)}) ---> updating the local variable while you are on the page

When going back to the previous page, use Navigate(previousPage, None, {selectedScore: score}) --> passing local variable back to the previous page

OnVisible property of the Previous Page use this formula Set(VarPriScore, selectedScore) --> everytime when the page becomes visible your global variable gets updated  to the value of the local variable


Hopefully that will solve your problem 🙂

Highlighted
Community Support
Community Support

Re: Setting Variable in If statement

Hi @Kevball2 ,

 

Could you tell me which control and property you use the formula to?

 

Please notice, Set function is a behavior formula, you can only use it in the formulas for the OnSelect, OnVisible, OnChange, and other On... properties.

 

To pass the score selected from dropdown, you can set your formula to OnChange property of dropdown.

 

Best regards,

Sik

View solution in original post

Highlighted
Frequent Visitor

Re: Setting Variable in If statement

Sik, 

 

Marking your response as the closest answer. I was attempting all the logic on the text box that was holding the score on screen. Text box's can't do the conditional update like i was trying to do.  Moving my logic up the chain to the 3rd drop down's OnChange event as @Jeff_Thorpe suggested.

 

is it better to handle the logic on a calculate button or on each drop down? the first 2 drop downs create a score based on the choices made there (a matrix of options) then multiplied by drop down 3. wanted the score to dynamically update but then i have to duplicate code in the top 2 drop downs so i may just move it all to a button for ease reading this code in 3 months :). Thanks everyone for their input! 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

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