Clear Sprint field on moving process

Hello,

when moving operations, the sprint field is not emptied. This causes the operations with wrong sprint on other boards. We have filter related boards. Is there a way I can clear the sprint field on the move? Is it possible with Scriptrunner? If yes how? And how can I use Scriptrunner to clear Cutomfields.

2 answers

2 votes

Here is sample code for a Move Issue event listener:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.UpdateIssueRequest

// optionally, check from/to project and conditionally execute...

def issueManager = ComponentAccessor.getComponent(IssueManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def sprintCf = customFieldManager.getCustomFieldObjectByName("Sprint")
def user = event.user

def issue = issueManager.getIssueObject(event.issue.id)
issue.setCustomFieldValue(sprintCf, null)
def updateIssueRequest = UpdateIssueRequest.builder().
eventDispatchOption(EventDispatchOption.DO_NOT_DISPATCH).
historyMetadata(null)

issueManager.updateIssue(event.user, issue, updateIssueRequest.build())

I have created a CustomListener and inserted the sample code. It worked. :-) There is also a possibility when cloning issues

Yes, it worked, because I tested it ;-) An upvote would be nice!

Which event needs to be trapped so that it can work when cloning? Thank yoimage.png

That's a more complicated question... see https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-detect-if-an-issue-is-a-clone-in-a-listener-at/qaq-p/562675. If you are on jira 7.5 you could do it on IssueLinkCreated and check if it's the cloners link I guess.

1 votes

Moving an issue tries to retain as much of the issue as the target project allows for, and as Sprint is a global field, it's not going to clear it.

You are right you can do it with ScriptRunner - a listener could be scripted to catch "issue moved", check you want to lose the sprint and clear it (and other fields) by setting them to "null".

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

857 views 5 18
Read article

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot