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.

YES, that helped! Thanks!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (1,361)