field_contains()

Test whether a field contains a given value. It picks the right kind of test from the shape of the value:

  • A list (multi-select, multi-user, multi-lookup) is a membership test: is that value one of the ones held?
  • Plain text (a text field, a single select, a comment body, a variable) is a case-insensitive substring test: does the text contain that phrase anywhere?

This means you don't have to know how the value is stored.

Syntax

field_contains(haystack, needle)

Parameters

Name Type Required Description
haystack array | string yes The value to search: a list, a single {id,title} object, or plain text.
needle string | array yes The value or phrase to look for. May be an {id,title} object (matched by id).

Returns

true if found, otherwise false. Comparisons are by string value, so "12" and 12 match. An empty needle never matches non-empty text.

Example

// list: is "urgent" one of the selected tags?
if ( field_contains($record["tags"], "urgent") ) {
    task_assign("tickets", $record["_meta"]["id"], $record["owner"], [
        "title" => "Urgent ticket needs triage"
    ]);
}

// text: does the comment body mention a refund anywhere?
if ( field_contains("{{comment.body}}", "refund") ) {
    log("refund mentioned");
}

Example output

true

Notes

  • Handles multi-select / multi-user lists, multi-lookup lists of {id,title} (matched by id), and single lookups.
  • List members match whole. Searching a tag list for "urg" will not match a tag called "urgent".
  • Text matching is case-insensitive, so "Refund" and "refund" both match.
  • This is the function behind the visual builder's contains / does not contain conditions.
  • To test that a field holds exactly one given value and nothing else, use flow_eq().

See also: flow_eq(), flow_text()