Script Runner Post function : Creates sub-task automatically - create sub-task based on fixversion

siva September 1, 2021

Hi there,

In my project workflow for a transition i added script runner postfunction to create automatic subt-task.

When i execute the workflow transition it creates the automatic sub-task. But i want create sub-task based on the fixversion value below you can see the  condition of existing script so please help me with this script create sub-task based on the fixversion. Please suggest me how to achieve this script.

import com.atlassian.jira.component.ComponentAccessor

 

def subtasks = issue.subTaskObjects

if(subtasks.find{it.summary == "Automated Test"})

{

return false

}

else

{

return true

}

 

 

Thanks,

Siva.

1 answer

1 accepted

1 vote
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

Hi @siva 

Fix Version field may keep multiple values, so you can check whether it contains a specific value as below (assuming 2.5.4 is the version you want to check):

if (issue.fixVersions*.name.contains("2.5.4")) {
return true
}

Hope it helps 

siva September 2, 2021

Hi @Tuncay Senturk 

Thank you very much for your reply. I tried your script but it throws the error  you can see the script below

import com.atlassian.jira.component.ComponentAccessor

if (issue.fixVersions*.name.contains("WiFi_2.7"))) {
return true
}

def subtasks = issue.subTaskObjects

if(subtasks.find{it.summary == "Automated Test"})

{

return false

}

else

{

return true

}

 

And the error logs are

The script could not be compiled:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script760.groovy: 3: unexpected token: ) @ line 3, column 51.
   ns*.name.contains("WiFi_2.7"))) {
                                 ^

1 error

erroe log.pngPlease let me know how to achieve this 

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

I am sorry there were too many closing braces.

Please try this one,

if (issue.fixVersions*.name.contains("2.5.4")) {
return true
}

I also corrected the above answer.

siva September 2, 2021

Hi thanks for the modification

I tried below script

import com.atlassian.jira.component.ComponentAccessor

if (issue.fixVersions*.name.contains("WiFi_2.7")) {
return true
}

def subtasks = issue.subTaskObjects

if(subtasks.find{it.summary == "Automated Test"})

{

return false

}

else

{

return true

}

And i tried the issue with different fixversion still it create the subtask. But i want create subtask based on fixversion (WiFi_2.7) is there any modifications in script

Thanks..

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

I don't have any idea why your test has not succeeded but below Groovy code means that if the version of the parent issue contains Wifi_2.7 value and any sub-task with summary "Automated Test" has not been created then return true, otherwise false.

 

return issue.fixVersions*.name.contains("WiFi_2.7")) && !issue.subTaskObjects*.find{it.summary == "Automated Test"}
siva September 2, 2021

Great the above script working perfectly thank you very much for your help also need one more favour in our project we had 10 to 20 fixversions all start with WiFi.

For example: 

WiFi_2.1, WiFi_2.2,WiFi_2.3, WiFi_2.4, WiFi_2.5, WiFi_2.6, WiFi_2.7, WiFi_2.8, WiFi_2.9, WiFi_2.10 and so on

Is there any possibility what ever Fixversion start with WiFi have to create Subtask

Thanks..

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

I am glad that it works!

Below would help your latter request:

return issue.fixVersions*.name.startsWith("WiFi_")) && !issue.subTaskObjects*.find{it.summary == "Automated Test"}

 

Please accept the answer so that it will be marked as RESOLVED.

Thanks

siva September 2, 2021

Hi @Tuncay Senturk 

Unfortunately the below script not working is there any changes to do

return issue.fixVersions*.name.startsWith("WiFi_") && !issue.subTaskObjects*.find{it.summary == "Automated Test"}

 Thanks

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

Oh sorry,

Try this one!

return issue.fixVersions*.any{it.name.startsWith("WiFi_")} && !issue.subTaskObjects*.find{it.summary == "Automated Test"}
siva September 2, 2021

Hi there,

Sorry, it's create subtask for every fixversion not for WiFi_ 

I think something change in script.

Thanks

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

I don't understand, you told me that you want to automatically create subtask if fixversion starts with WiFi_. 

The Script above checks exactly if any of the fixversions starts with WiFi and there is no already created sub task with summary 'Automated Test'.

Am I missing something?

siva September 2, 2021

Hello,

yes it is creating sub task for the fix versions start with “WiFi”. But it is also creating sub task for other fix version names.

For example: We have fix version name called SDN  and sub task is creating for SDN as well with above script.

Thanks

siva

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

If an issue has fix versions of WiFi_2.7 and SDN_1.4 it creates one subtask.

But if it has only SDN_1.4 it should not create a subtask

Is this what you want?

siva September 2, 2021

If it is only WiFi_2.7then only sub task need to create. Not for SDN_1.4


Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

In your example, the issue has no fixversion starting with WiFi, and it has only a fixversion starting with SDN, but it created a subtask using the script below. Is that correct?

return issue.fixVersions*.any{it.name.startsWith("WiFi_")} && !issue.subTaskObjects*.find{it.summary == "Automated Test"}
siva September 2, 2021

What i'm say is if the issue has only one fixversion that is SDN_2.8 (here i didn't add secondary fixversion like WiFi_2.7) and if we execute transition it creating the subtask. But actually condition is create subtask only for WiFi_

Here attaching the screen shot below

fixversion.png

We can seen in screen shot fixversion is SDN_2.8 but still it creating the subtask.

Thanks

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

Ok I see, that's because of the asterisk (*) character.

Please try this one,

return issue.fixVersions.any{it.name.startsWith("WiFi_")} && !issue.subTaskObjects*.find{it.summary == "Automated Test"}
siva September 2, 2021

Thank you for your help it's working perfectly very appreciated

 

Thanks a lot

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

Wow! Finally we figured out the little mistake (*) :) 

I am glad it worked.

siva September 8, 2021

Hi @Tuncay Senturk I hope you doing good,

The script which you share working perfect here the scriot

return issue.fixVersions.any{it.name.startsWith("WiFi_")} && !issue.subTaskObjects*.find{it.summary == "Automated Test"}

it creates subtask based on fixvrersion. But here I'm facing a small issue, if issue already  had a subtask with different summary name it's not creating the our scripted subtask.

For example:

If issue had a subtask and summary is "Automated Test" then it can't create subtask.

If  issue had a subtask and summary is " some thing else" then it creates subtask. But our present script not creating subtask if it had different summary name.

Please help me with this  how to solve this issue.

Thanks,

Siva

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 8, 2021

Good point, please try this one

 

return issue.fixVersions.any{it.name.startsWith("WiFi_")} && !issue.subTaskObjects.any{it.summary == "Automated Test"}
siva September 8, 2021

Wow thanks now it's working perfect 

Thank you very much.

Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2021

Happy to help :) 

Suggest an answer

Log in or Sign up to answer