ScriptRunner Post-Function: Create Subtask Condition from Multi-select field

Timothy Ryner September 30, 2019

I am trying use Scriptrunner's "Create a sub-task" post-function to automatically create a subtask on a particular transition, and I'm having difficulty writing the condition. 

  • For MultiSelectField with 4 options (Option1, Option2, Option3, Option4):
    • Create a Subtask if Option1, Option2, and/or Option3 is selected. 
    • Do not create a Subtask if Option4 is selected (unless 1, 2, 3 is also selected).
    • Do not create multiple subtasks for each option, just one if 1, 2, 3 has been selected.

The Example Condition provided by ScriptRunner is close, but it only seems to work for one option, and I haven't figured out the syntax for multiple options.

SCRIPTRUNNER EXAMPLE

'My Value' in cfValues['My Multi List']*.value

Any help is greatly appreciated!

(Jira Server 7.9.2, ScriptRunner v5.4.12)

1 answer

1 accepted

2 votes
Answer accepted
Ravi Sagar _Sparxsys_
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.
October 3, 2019

Hi @Timothy Ryner 

Try this code.

def values = cfValues['My Multi List']*.value
if ( values.contains('Option 1') || values.contains('Option 2') || values.contains('Option 3')) {
return true
} else {
return false
}
Timothy Ryner October 3, 2019

@Ravi Sagar _Sparxsys_ , you have a gift, my friend.  Worked exactly as needed.

Like Ravi Sagar _Sparxsys_ likes this
Mahesh Kallepalli January 21, 2020

@Timothy Ryner 

I got same requirement can you please enhance full code to achieve as I'm new to script runner.

Omari Ledeatte-Williams January 11, 2021

Hi @Mahesh Kallepalli , Did you manage to solve this, I am also new to script runner and have something similar.

Suggest an answer

Log in or Sign up to answer