The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

post function custom script?

Ghazi Ben Jalel
July 18, 2017

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Thanos Batagiannis _Adaptavist_
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 Champions.
August 2, 2017

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.bc.issue.search.SearchService
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 = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.issues.collect { issueManager.getIssueObject(it.id) }
}

//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, 

Thanos