How to use "OR" condition in Script Post-Function Create a sub-task (Scriptrunner)

Camille Lecerf April 10, 2018

Hi,

I would like to use a simple "OR" in the condition of the Script Post-Function Create a sub-task (Scriptrunner):

('Value1' in cfValues['CustomFieldName']*.value || 'Value2' in cfValues['CustomFieldName']*.value)

But it does not work...

This one works:   'Value1' in cfValues['CustomFieldName']*.value

I am using this Post-Function in a workflow on the Create transition.

Thank you for your Help !

Camille

1 answer

1 accepted

1 vote
Answer accepted
Carmen Creswell [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2018

Hi Camille!

What type is the CustomFieldName? Different custom field types return different values. For example, if CustomFieldName is a plain text field, using 'in' and '*.value' returns a list of strings and will only check if your value is in the list. 

For example: "The quick brown fox jumps over the lazy dog"*.value returns :  

[T, h, e,  , q, u, i, c, k,  , b, r, o, w, n,  , f, o, x,  , j, u, m, p, s,  , o, v, e, r,  , t, h, e,  , l, a, z, y,  , d, o, g, .]

The way that you have the code typed, your 'CustomFieldName' will probably need to be a type like MultiSelect. 

Camille Lecerf April 10, 2018

Hi Carmen !

The customfield is a Checkbox. Is there a solution for that type of field please ?

Carmen Creswell [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2018

The code you published in the original query works with a Checkbox for me! If you can, post a screenshot of the actual code you have in the script. That way, I can try to recreate the error. If you can provide the execution history of the Post function, that could also be helpful as well. 

Camille Lecerf April 10, 2018

I found my error. The correct syntax for my checkbox customfield was that one :

(cfValues['CustomFieldName']*.value.contains("Value1") || cfValues['CustomFieldName']*.value.contains("Value2"))

Thank you Carmen this was indeed a matter of customfield type !

Suggest an answer

Log in or Sign up to answer