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
Solved! Go to Solution.
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.
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!
User | Count |
---|---|
253 | |
109 | |
92 | |
48 | |
37 |