It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Greenhopper/Groovy: Can I set the Greenhopper 'Sprint' field to null using groovy post functions?

Donncha Daly Dec 11, 2012

Hi,

Upon certain transitions, I am cloning an issue from one project to another using the Groovy Runner 'Clones and issue and links' function. However when the issue arrives in the new project it is still associated with the sprint from the originating project (GHS-5098)

My question is, can I use the 'Additional Actions' section of the 'Clones and issue and links' function to set the 'Sprint' field to null. When I do this manually it removes the issue from the originating sprint and places it in the backlog of the new project where it belongs.

I hope this is possible as this is a really annoying bug.

7 answers

1 accepted

2 votes
Answer accepted
JamieA Dec 11, 2012

If you need to unset it just try setting it to null:

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'}
issue.setCustomFieldValue(cf, null)

If you need to set it to a specific sprint you may need: sprintManager.getSprint(id) or something...

Donncha Daly Dec 12, 2012

thanks again

Kate McAnespie Jul 01, 2015

It seems if you null out Sprint, you cannot also set another custom field in the same additional action box or clone and link fails.

JamieA Jul 01, 2015

it should not fail... can you provide the code and exception.

Kate McAnespie Jul 02, 2015

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'} issue.setCustomFieldValue(cf, null); def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Story Points'} issue.setCustomFieldValue(cf, null);

JamieA Jul 02, 2015

you can't redeclare cf... def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'} issue.setCustomFieldValue(cf, null); cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Story Points'} issue.setCustomFieldValue(cf, null);

Kate McAnespie Jul 02, 2015

oh wow silly mistake! thanks!

0 votes
Donncha Daly Dec 11, 2012

I should note that my srcipting skills are fairly limited so I am asking both 'Is it possible' and 'How would I do it'

0 votes
JamieA Dec 11, 2012

All I can say is yes it is possible... personally I don;t have time to write the code. The sprint is some custom field, it should just be a case of finding the ID for that and nulling it out.

0 votes
Donncha Daly Dec 11, 2012

Just looking into this a bit more, I think the Sprint field may be restricted somehow. For any other customfields I can just use the 'Set custom field' function in the Additional actions section of the 'Clones and issue and links' function i.e.

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'SomeField'}
issue.setCustomFieldValue(cf, 'Some text')

and this works fine.

However when I use

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'}
issue.setCustomFieldValue(cf, 'Sprint name')

not only does it not change the sprint field, it doesn't complete the clone and link function.

0 votes
JamieA Dec 11, 2012

That's interesting... any log messages? You're trying to set it to a string, possibly that's not what it wants...

0 votes
Donncha Daly Dec 12, 2012

Hi Jamie,

Once again, your answer works. Thank you very much, your work on groovy runner and your answers to questions on this forum are much appreciated (as evidenced by your karma count)

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Sprint'}
issue.setCustomFieldValue(cf, null)

sets the value in the Sprint field to null, thereby forcing the cloned issue into the backlog of its new project as opposed to moving to the new project and remaining in the originating project's sprint.

If you could convert your comment to an answer I will mark it as 'answered'

0 votes
JamieA Dec 12, 2012

Done, thanks Donncha. I copied your code to the answer for completeness...

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Webinar invitation: Generate custom Jira Cloud PDF reports and exports

Jira may be a staple part of your workday, but your colleagues, customers, business partners or an auditor might need information presented in a different format, that is easy to access and read. And...

64 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you