Articles in this section

How to determine if the source text contains a specific search value using Contains()

This article explains what the Contains() operator is and provide examples of how it can be used with the binding syntax in smart templates.

  Prerequisites

  • Library and at least one Dynamics module enabled.
  • Templafy Desktop and Office VSTO add-in installed.
  • Space owner access to the Templafy tenant.

What is the Contains() operator?

Contains() is an operator that returns True/False depending on a Source value containing a Search value. Contains() is case sensitive, comparisons between two values that might be using different casings can be achieved by using a Lower() or Upper() function together with Equals().

Contains() logic

Syntax {{Contains(SourceValue, SearchValue)}}
Output True/False

Contains() operator examples

Example 1

Using the Contains() operator to check if a sentence contains the word "random" (case-sensitive).

Binding {{Contains("This is a longer sentence with some random text", "random")}}
Output True
Binding {{Contains("This is a longer sentence with some Random text", "random")}}
Output False

Example 2

Using the Contains() operator together with Lower() to match the casing used and make a comparison.

Binding {{Contains(Lower("This is a longer sentence with some random text"), Lower("Random"))}}
Output True

Example 3

Using the Contains() operator together with Not() and Lower() to match the casing used and make a comparison.

Binding {{Not(Contains(Lower("This is a longer sentence with some random text"), Lower("Random")))}}
Output False

Example 4

Using the Contains() operator together with IfElse() and Lower() to verify if the input entered in the "Body" question originating from the response form contains the word "legal" (not case-sensitive as the Lower() function is used). If the "Body" contains "legal" the output should be "There is legal text in the above document. Ensure it's legally compliant.", otherwise insert an empty input.

Binding {IfElse(Contains(Lower(Form.Body), "legal"), "There is legal text in the above document. Ensure it's legally compliant.", "")}}
Input Form.Body = "This is legal text." Form.Body = "This is marketing text."
Condition True False
Output "There is legal text in the above document. Ensure it's legally compliant." ""

Example 5

Using the Contains() operator together with IfElse() to display or hide some text based on the value of the "Office.Name" originating from the User Profile.

  • If the "Office.Name" is "Copenhagen" or "Berlin", the text should be hidden.
  • If the "Office.Name" is anything else, the text should be shown.
Binding {{IfElse(Contains("Copenhagen, Berlin", UserProfile.Office.Name), VisibilityType.Hidden, VisibilityType.Visible)}}
Input UserProfile.Office.Name = "Berlin" UserProfile.Office.Name = "Copenhagen" UserProfile.Office.Name = "Eindhoven"
Output Hidden text Hidden text Visible text

Example 6

Using the Contains() operator together with IfElse() to see if the "Subject" question originating from the response form matches any of the comparison values (large, cat, small, dog). If the values are "large", "small", "cat", or "dog", the output should be "Match", otherwise "No match" should be shown.

Binding {{IfElse(Contains("large cat, small cat, dog", Form.Subject), "Match", "No match")}}
Input cat Cat large cat small cat dog fox
Condition True False True True True False
Output "Match" "No match" "Match" "Match" "Match" "No match"

Based on the example above, you can also add the Concat() function to see if the "Subject" question originating from the response form matches exactly any of the comparison values (large cat, small cat, dog). If the values are "large cat", "small cat", or "dog", the output is "Match", otherwise "No match" is shown.

Binding {{IfElse(Contains("##large cat##, ##small cat##, ##dog##",Concat("##",Concat(Form.Subject,"##"))), "Match", "No match")}}
Input cat Cat large cat small cat dog fox
Condition False False True True True False
Output "No match" "No match" "Match" "Match" "Match" "No match"

  Note

  • In this example, the output for "cat" is "No match", because "cat" is neither equal to 'large cat' or 'small cat'. It is not an exact match.
  • Instead of '##' any other characters can be used, e.g. '@' or '+++'.

Example 7

Using the Contains() operator together with IfElse() to see if the "Subject" question originating from the response form matches any of the comparison values (large, cat, small, dog) and adjust the text visibility. If the values are "large", "small", "cat", or "dog", the output should be shown, otherwise, it should be hidden.

Binding {{IfElse(Contains("large cat, small cat, dog", Form.Subject), VisibilityType.Visible, VisibilityType.Hidden)}}
Input cat Cat large cat small cat dog fox
Condition True False True True True False
Output Visible Hidden Visible Visible Visible Hidden

Based on the example above, one can also add the Concat() function to see if the "Subject" question originating from the response form matches exactly any of the comparison values (large cat, small cat, dog) and adjust the text visibility. If the values are "large cat", "small cat", or "dog", the output should be shown, otherwise, it should be hidden.

Binding {{IfElse(Contains("##large cat##, ##small cat##, ##dog##",Concat("##",Concat(Form.Subject,"##"))), VisibilityType.Visible, VisibilityType.Hidden)}}
Input cat Cat large cat small cat dog fox
Condition False False True True True False
Output Hidden Hidden Visible Visible Visible Hidden

  Note

  • In this example the output for 'cat' is Hidden text, because 'cat' is neither equal to 'large cat' or 'small cat'. It is not an exact match.
  • Instead of '##' any other characters can be used, e.g. '@' or '+++'.
sensitivity reference tech_role
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.