Page 1 of 1

GetLabeledText check if empty

Posted: 05 Mar 2019 16:49
by JoopvB
I am in the process of changing over to GetLabeledText for my "meta fields" in the sentence definition of the various fact types. Overall this is going very well but I've run into a small problem. When I test whether a "meta field" has no input, the test doesn't work.

I tried:
{=TextIf(Exists(GetLabelledText(%FACT.NOTE2%,"Impost: ")),"text1", "text2")}

I can imagine that the CR at the end of the line makes the test fail. If so, what other test can be used to accomplish conditional text as depending on the GetLabeledText approach? Or, am I overlooking the obvious and is the statement just wrong?

Re: GetLabeledText check if empty

Posted: 05 Mar 2019 18:01
by JoopvB
Yes, the statement is wrong. I should have used:

{=TextIf((GetLabelledText(%FACT.NOTE2%,"Impost: ")=""),"text1", "text2")}

Sorry for my dumb question.

Re: GetLabeledText check if empty

Posted: 05 Mar 2019 18:42
by Jane
No such thing as a dumb question and thanks for posting your solution as well.

The reason is that Exists() checks for a Data Item (in Lua terms a pointer) so checking a Text string always fails.

Re: GetLabeledText check if empty

Posted: 05 Mar 2019 19:42
by davidf
Jane wrote:No such thing as a dumb question and thanks for posting your solution as well.

The reason is that Exists() checks for a Data Item (in Lua terms a pointer) so checking a Text string always fails.
That is a useful answer! So the question must have been useful because it flushed it out!

Re: GetLabeledText check if empty

Posted: 05 Mar 2019 23:48
by tatewise
An alternative (more conventional & more efficient) approach is to ensure one of the following exists in the Note field:

Impost: text1

Impost: text2

Impost:

Then {=GetLabelledText(%FACT.NOTE2%,"Impost: ")} will display either text1 or text2 or nothing.

Using this method the text can take any number of different values.
Whereas your technique gets extremely cumbersome if there are more than two possible text values.

Re: GetLabeledText check if empty

Posted: 06 Mar 2019 09:35
by JoopvB
@Mike

Yes, and that's what I use. But, I see now my question was confusing. In addition to what you (and I ) use to get the "meta field" input, I also use the fact that there is an input to the "meta field" to decide which text to use on a different position in the sentence. Hence the test.