post function custom script?

Do you have an idea of how to write a script to remove sprint fields for each created issue if IssueFunction in hasLinkType (cloners) ? I have chosen custom script post function but not sure about the code itself

1 answer

Hi Ghazi,

So if you want to clean the sprint in "one go" you can run the following script in your script console 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.web.bean.PagerFilter

def issueManager = ComponentAccessor.getIssueManager()
def searchService = ComponentAccessor.getComponent(SearchService)
def customFieldManager = ComponentAccessor.customFieldManager

def jqlSearch = """
IssueFunction in hasLinkType ("Cloners")

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issues = []

SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
def searchResult =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.issues.collect { issueManager.getIssueObject( }

//for all the issues returned from the JQL above clear the sprint field
issues?.each { issue ->
def sprint = customFieldManager.getCustomFieldObjectByName("Sprint")
if ( issue.getCustomFieldValue(sprint) ) {
def changeHolder = new DefaultIssueChangeHolder()
sprint.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(sprint), null),changeHolder)

Now if you want to cleat the spint from a sinlge issue during a tranisstion that you will need a custom script post function with the following script 

import com.atlassian.jira.component.ComponentAccessor

// if that issue has at least one Cloners link then clear the sprint value
def hasCloner = ComponentAccessor.getIssueLinkManager().getLinkCollectionOverrideSecurity(issue).linkTypes*.name.contains("Cloners")
if (hasCloner) {
def sprint = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Sprint")
issue.setCustomFieldValue(sprint, null)

Kind regards, 


Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,063 views 13 18
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
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