* Having issues using "ContainsText" function

Questions about Generic and Templated Sources within FH and their associated Citations and Repositories
Post Reply
avatar
Gary_G
Megastar
Posts: 756
Joined: 24 Mar 2023 19:05
Family Historian: V7

Having issues using "ContainsText" function

Post by Gary_G »

I have a source record template text field called {Ref} and need to scan it for a unique sequence of characters (let's say "(TEXT)"), then set a returned text string to "A" (if found) or default to "B" (if not found).

The following has been tried, but "ContainsText" always seems to return False, which results in "B" being shown.

{=TextIf(ContainsText(%SOUR.~TX-Ref%, "(TEXT)", STD), "A", "B")}.

I've read over the documentation, but must still be using the functions incorrectly. Unfortunately; I can't see the issue. Has anyone any suggestions?
Gary Gauthier
Hunting History in the Wild!
User avatar
tatewise
Megastar
Posts: 28488
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Having issues using "ContainsText" function

Post by tatewise »

In the Help page Understanding Data References it says to use the field code name in uppercase.
i.e. ~TX-REF

Where is the {=TextIf(...)} function used?
Is it in a Source Template Definition Footnote/Bibliography Format template expression?
If so then the above correction should fix the problem.
If anywhere else then the SOUR record must be identified. I'll need to know the context to give more details.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
Gary_G
Megastar
Posts: 756
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: Having issues using "ContainsText" function

Post by Gary_G »

Mike;

I'll try using upper case and post again.

In my question, I addressed most of your questions; " have a source record template text field called {Ref} and need to scan it for a unique sequence of characters..."

The place where the result is to be used can be in any of the Title, Footnote, Subsequent Footnote and Bibliography.
Gary Gauthier
Hunting History in the Wild!
avatar
Gary_G
Megastar
Posts: 756
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: Having issues using "ContainsText" function

Post by Gary_G »

Seems that capitalizing the referenced metafields had no effect.
Also checked non-capitalized metafield references in other templates and they work fine... odd.
Gary Gauthier
Hunting History in the Wild!
User avatar
tatewise
Megastar
Posts: 28488
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Having issues using "ContainsText" function

Post by tatewise »

Yes, but you could have been scanning the {Ref} field in a Query Column or Row expression or in a Records Window tab Column or in a Diagram Text Scheme or Boxes Condition or in a Sentence Template. In fact, anywhere an expression is allowed. The only clue I had was its enclosure in { curly brackets } which suggested my first question, but that may have been a syntax error and part of the problem.

Please post a screenshot of your use of the expression. That is far better than trying to explain its context.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
Gary_G
Megastar
Posts: 756
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: Having issues using "ContainsText" function

Post by Gary_G »

The following is a screenshot of the use-case with the section in question being highlighted.
The noted portion was just patched in to the just the Title portion in order to see if I could get it working.
While the rest of the template works fine, it won't be brought into line with the final design until I can get the code in question working.
Attachments
Test Template
Test Template
Screenshot 2024-03-06 at 11.35.01 AM.png (186.07 KiB) Viewed 277 times
Gary Gauthier
Hunting History in the Wild!
User avatar
tatewise
Megastar
Posts: 28488
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Having issues using "ContainsText" function

Post by tatewise »

Ah! You and many others (and I) have fallen into this popular trap!

=ContainsText(...) checks a specified record’s text fields to see whether it contains text that matches a given search text. But you are not searching in a record. You are searching in a metafield.

So you must use the =FindText(...) function that returns the position of a specified search string within another string. Returns 0 if the search string is not found.
i.e.
{=TextIf( FindText(%SOUR.~TX-REF%, "(TEXT)") > 0, "A", "B" )}
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
Gary_G
Megastar
Posts: 756
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: Having issues using "ContainsText" function

Post by Gary_G »

Thank you, Mike.
That possibility had crossed my mind, but the document didn't really highlight that aspect and so I missed it.
Gary Gauthier
Hunting History in the Wild!
User avatar
tatewise
Megastar
Posts: 28488
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Having issues using "ContainsText" function

Post by tatewise »

As an experiment, I tried {=TextIf(ContainsText(%SOUR%, "(TEXT)", STD), "A", "B")}

That then works if any Source record text field contains (TEXT) but that is not what you wanted.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
Gary_G
Megastar
Posts: 756
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: Having issues using "ContainsText" function

Post by Gary_G »

I'm just putting together a dummy template with the one field and the code entered in the Title, Bibliography, Footnote and Short Footnote. That way; Nothing else can affect whether it works or not. Am doing this, because the following didn't appear to work.

{=TextIf( FindText(%SOUR.~TX-REF%, "(TEXT)") > 0, "A", "B" )}
Gary Gauthier
Hunting History in the Wild!
avatar
Gary_G
Megastar
Posts: 756
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: Having issues using "ContainsText" function

Post by Gary_G »

Mike;

I had a terrible time getting the new code to work. It took several tries, but finally it did.
There must have been some hidden characters in the cut and pasted code, because it worked when I entered it directly into the template design field for the title. Must watch out for this in future.

Thank you for your help.
Gary Gauthier
Hunting History in the Wild!
User avatar
tatewise
Megastar
Posts: 28488
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Having issues using "ContainsText" function

Post by tatewise »

Sometimes the string quotes " character in these postings is not the same as FH expects.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
Gary_G
Megastar
Posts: 756
Joined: 24 Mar 2023 19:05
Family Historian: V7

Re: Having issues using "ContainsText" function

Post by Gary_G »

Yes; I've noticed that the quotes can be an issue.
That said; I'm thankful for your help, Mike.
The main issue was driving me crazy and now it's fixed.
Gary Gauthier
Hunting History in the Wild!
Post Reply