SEARCH
Use the SEARCH function to find the starting position of one text value within another text value, returning the position of the first character of the first text value in the second text value.
Use
SEARCH( find_text , within_text [, start_num] )
Finds the position of one text value within another (case-insensitive).
| Parameter | Required | Description |
|---|---|---|
| find_text | Yes | the text to find |
| within_text | Yes | the text to search |
| start_num | No | specifies the character at which to start the search (starting from 1) |
| Returns | Number |
Examples
Verifying Mandatory Keywords (Output Validation)
You can use SEARCH in an Output Validation formula to ensure a user has included a specific keyword within a form field, such as a "Description" or "Notes" field.
- Scenario: A "Service Request" form requires that the user mentions the word "Urgent" somewhere in their notes if they want a priority response.
- Formula:
ASSERT(SEARCH("Urgent", this) > 0, "If this is a priority request, the word 'Urgent' must be included in your notes."). - Logic: Because SEARCH is case-insensitive, it will return a match if the user types "URGENT," "urgent," or "Urgent".
- Result: If the word is found, the function returns the character position (a number greater than 0), and the validation passes. If the word is missing, the ASSERT function triggers the error message.
Locating Data for Extraction (Input Mapping)
In Input Mapping, the SEARCH function is often used to find the "anchor point" for specific data buried within a larger block of text.
- Scenario: A Trigger form captures a "Full Reference" string, such as "REF-ID: 10293-Finance." You want to find where the ID number starts so you can later extract it using the
MIDfunction. - Formula:
SEARCH("ID:", @Trigger.out.FullReference). - Logic: The function scans the text provided by the trigger.
- Result: It returns the character position where "ID:" begins (in this case, position 5). You can then use this number as the
start_numin aMIDfunction to extract the digits that follow.
Pro Tip: The SEARCH function also supports an optional third parameter, start_num, which specifies the character at which to start the search. This is useful if you know the keyword you are looking for might appear multiple times and you only want to find the occurrence that happens after a certain point in the string.