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
Anonymous
Not applicable

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
Anonymous
Not applicable

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.

YES, that helped! Thanks!

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 (4,002)