cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
German_Chris
Helper I
Helper I

One Variable with TWO Values?

In my App I have to check if the user enters some spezific "strings" in a RichTextEditor.
Which strings this are I have to search in at HTMLText-Control.

In this control I seach the words "Must=(" and the ")" between this brackets are the "stings" (in the following example this are numbers, but this is not relevant I think).

 


I have a Button with the following code: 

If(!IsBlank(Find("Must="; HtmlText_Comments.HtmlText));

UpdateContext({
    varCheckMustCommentFrom:Find("Must=" & Char(40);HtmlText_Comments.HtmlText)+6; 
    varCheckMustCommentTo: Find(Char(41);HtmlText_Comments.HtmlText; varCheckMustCommentFrom);
    varCheckMustCommentText: Mid(HtmlText_Comments.HtmlText;varCheckMustCommentFrom;varCheckMustCommentTo- varCheckMustCommentFrom);
    varCheckMustCommentArray: Split(Substitute(varCheckMustCommentText;" ";"");";")
});;


ClearCollect(colCheckMustComment; AddColumns(varCheckMustCommentArray As varsearch; "Found"; !IsBlank(Find(varsearch.Result; RichTextEditor2.HtmlText))));;
UpdateContext({varCheckMustComment: Sum(colCheckMustComment; Found) > 0})
;UpdateContext({varCheckMustComment: true}))

 

My problem is, that I have to push the Button 3-times (no other click anywhere in the app) until the last variable gets the correct value. I do not understand why.

 

What I found is, that that (please see the below picture) 
(3) variable: varCheckMustCommentText has the correct value "1099; 1249"
(4) variable: varCheckMustCommentArray is empty!!!
     I checked here the value from varCheckMustCommentText in the Split()-Function. And here the Variable is EMPTY

As above mentioned, if I click the butten twice more times, the variable has the value "1099; 1249" as expected

SearchStrings2.png

1 ACCEPTED SOLUTION

Accepted Solutions
Colby
Advocate I
Advocate I

To fix this separate your variables out into separate UpdateContext calls. Example:

UpdateContext({varCheckMustCommentText: stuff});

UpdateContext({varCheckMustCommentArray: stuff});

 

Basically what is happening is Power Apps is calling this function in one go. So because varCheckMustCommentArray references the varCheckMustCommentText (which is null before it is set) because it is referencing the other variables that are null initially before they are set as well. So if you call the function separately for each variable it will set each one as it runs synchronously down through each UpdateContext function.

 

Hopefully that sort of makes sense.

View solution in original post

2 REPLIES 2
Colby
Advocate I
Advocate I

To fix this separate your variables out into separate UpdateContext calls. Example:

UpdateContext({varCheckMustCommentText: stuff});

UpdateContext({varCheckMustCommentArray: stuff});

 

Basically what is happening is Power Apps is calling this function in one go. So because varCheckMustCommentArray references the varCheckMustCommentText (which is null before it is set) because it is referencing the other variables that are null initially before they are set as well. So if you call the function separately for each variable it will set each one as it runs synchronously down through each UpdateContext function.

 

Hopefully that sort of makes sense.

View solution in original post

YES, that helped! Thanks!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,727)