In my automation I'm calling the Atlassian API and want to populate a variable based on the following condition:
{{if(or(webResponse.body.id.contains("customfield_1"),webResponse.body.id.contains("customfield_2")),"fieldsPresent","fieldsNotPresent")}}
Thanks all, I went with a nested IF clause to filter for the events I'm interested in. It's quite astounding that smart values don#t support contains keyword, but oh well.
.contains() function seems to exist and work (at least for strings), but yeah, seems to have disappeared from docs?
This works for me right now in an automation rule:
1. Set variable varTest to: Hello, World!
2. Log action: {{if(varTest.contains("World!"),"Yes","No")}}
Logs: Yes
3. Log action: {{if(varTest.contains("Word"),"Yes","No")}}
Logs: No
4. Log action: {{if(varTest.contains("Hello,"),"Yes","No")}}
Logs: Yes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For a question like this, context is important for the community to help. Please post the following:
Until we see those...
Would you please confirm, are you testing for a match to the value of custom fields in the web response body, or to the literal text "customfield_1"?
And, there is no contains() function in smart values, and thus other methods must be used.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jared Schmitt
Yes, the "contains" is not supported.
Instead, you can try to use match()
{{if(or(webResponse.body.id.match("customfield_1"),webResponse.body.id.match("customfield_2")),"fieldsPresent","fieldsNotPresent")}}
Please try the above-mentioned one.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for the fast reply. I tried that and didn't change the result.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear @Jared Schmitt
If match() also didn't work, it can be because it wasn't applied to a string.
Try this one, please.
{{if(
gt(
webResponse.body.asJsonString.match("(customfield_(?:1|2))").size,
0
),
"fieldsPresent",
"fieldsNotPresent"
)}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.