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

Donncha Daly December 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
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.
December 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 December 12, 2012

thanks again

Kate McAnespie July 1, 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
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.
July 1, 2015

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

Kate McAnespie July 2, 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
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.
July 2, 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 July 2, 2015

oh wow silly mistake! thanks!

0 votes
JamieA
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.
December 12, 2012

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

0 votes
Donncha Daly December 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
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.
December 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 December 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
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.
December 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 December 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'

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events