Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Suggested Answer
+1
person also asked this
people also asked this
Replies
15 replies
Answers
2 answers
Subscribers
8 subscribers
Views
21700 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Expression evaluation error at function 'contains' [line 39]: Invalid types, can only act on data of the same type (Any Type, Text)
eliav
over 7 years ago
Hello All,
I need to read an array extracted by a datasubset just to know if it contains a particular string
Following the code
contains(
index(
local!datasubset.data,
"status",
null
)
,"TO DO")
I have this eror
Expression evaluation error at function 'contains' [line 39]: Invalid types, can only act on data of the same type (Any Type, Text)
How can I do ?
Thanks
Elia
OriginalPostID-253930
Discussion posts and replies are publicly visible
Top Replies
Stefan Helzle
over 7 years ago
+2
suggested
A Score Level 3
You can use the function touniformstring() to convert a list of any data to a list of strings. tostring() concatenates all items to a single string.
PhilB
over 7 years ago
+1
A Score Level 1
Try wrapping the index() function in tostring().
Mike Schmitt
over 7 years ago
+1
suggested
Certified Lead Developer
Be careful - contains() expects its first parameter to be an array, and in this case it's an array of the property "status" from your datasubset. Wrapping this in "tostring()" will cause the whole array…
0
PhilB
A Score Level 1
over 7 years ago
Try wrapping the index() function in tostring().
Cancel
Vote Up
+1
Vote Down
Sign in to reply
Verify Answer
Cancel
0
rodgraham
Certified Lead Developer
over 7 years ago
You can use the cast function on the status to convert it to text to allow the use of contains
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Rama Thummala
Certified Lead Developer
over 7 years ago
@eliav
Here index() returns AnyType value. For contains() you are passing AnyType value and Text value, so it is giving error. convert the output of index() to Text either by using tostring() or cast('type!{namespace}Text' ,index() output )
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Ram
Certified Lead Developer
over 7 years ago
Hi Elia,
Try the below code snippet replacing the data in index function and contains search value.
I hope this will help you.
contains(
split(index({
{
name: "aaa",
age: 21
},
{
name: "bbb",
age: 22
}
}, "name", null), ";"),
"aaa"
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
+1
Mike Schmitt
Certified Lead Developer
over 7 years ago
Be careful - contains() expects its first parameter to be an array, and in this case it's an array of the property "status" from your datasubset. Wrapping this in "tostring()" will cause the whole array to be converted into one concatenated string, in which case your contains() call will return FALSE in cases where it should return TRUE.
I think the proper rule to use in this case would be 'touniformstring()', which converts an array into an array of strings.
Cancel
Vote Up
+1
Vote Down
Sign in to reply
Verify Answer
Reject Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 7 years ago
You can use the function touniformstring() to convert a list of any data to a list of strings. tostring() concatenates all items to a single string.
Cancel
Vote Up
+2
Vote Down
Sign in to reply
Verify Answer
Reject Answer
Cancel
0
eliav
over 7 years ago
Ok, but I have a strange behaviour
contains(
tostring(
index(
local!datasubset.data,
"status",
null
)
),
"TO DO"
),
Doesn't work , TO DO value is not found (returned value is false)
If I try
contains(
{"TO DO"; "DONE"; "DONE"; "DONE"} , "TO DO")
it works and the returned value is true
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
PhilB
A Score Level 1
over 7 years ago
Apologies - the guys are right, I should have said touniformstring() :)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Mike Schmitt
Certified Lead Developer
over 7 years ago
A valid code snippet should be something like:
contains(
touniformstring(
property(
local!datasubset.data,
"status",
{} /*null*/
)
),
"TO DO"
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 7 years ago
contains(
touniformstring( <--------
index(
local!datasubset.data,
"status",
null
)
),
"TO DO"
),
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
>