Skip to main content
swapnar6405
April 4, 2023
Solved

How to check a string existing in a list of strings

  • April 4, 2023
  • 2 replies
  • 0 views

Hi,

I have a code like below where I am getting a list of text strings into a local!leadIDs. When I try to use contains() function to check whether a specified string exists, then I am getting an error like 

Expression evaluation error at function 'contains' [line 11]: Invalid types, can only act on data of the same type (Any Type, Text)

Can someone advise, how to fix this.

a!localVariables(
local!leadIDs: index( rule!getLeads(key: null()), "id", null()),
contains(local!leadIDs, "AB12345")
)

Expression evaluation error at function 'contains' [line 11]: Invalid types, can only act on data of the same type (Any Type, Text)

    Best answer by mikes0011

    contains() is finnicky about data types - you should try the following:

    contains(
      touniformstring(local!leadIds),
      "ABCDEFG"  /* etc */
    )

    This will force-cast "local!leadIDs" to "array of string" type instead of "array of any type", and will not trip up contains().

    2 replies

    mikes0011
    mikes0011Answer
    Brainy
    April 4, 2023

    contains() is finnicky about data types - you should try the following:

    contains(
      touniformstring(local!leadIds),
      "ABCDEFG"  /* etc */
    )

    This will force-cast "local!leadIDs" to "array of string" type instead of "array of any type", and will not trip up contains().

    January 4, 2024

    That was a HUGE help. I have been struggling immensely with how picky contains is with the types. I have been doing casting, until I stumbled upon a situation in which something simply refused to cast to an array of text. This solved by problem, bypassing the need to cast.