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

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

Accepted Answer
2 votes

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...

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.

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

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);

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);

oh wow silly mistake! thanks!

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

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.

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

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

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

3,015 views 6 6
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you