Seek assistance writing a Scriptrunner script that sets/clears the Resolution globally based on Status Category, without using Post Functions.
- When an issue is transitioned (any issue in the instance, in any project)
- If Status Category is in "To Do" or "In Progress"
- Resolution is cleared, set to "None" (empty).
- If Status Category is in "Done"
- the Resolution is set to "Done".
+ Also, have the ability to limit the script to certain projects initially for testing, before enabling globally.
++ We have the Automation plugin, which is a good candidate for simply executing the script on the Issue Transitioned event, and also allows for project-level implementation.
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor
def is = ComponentAccessor.issueService
def iip =is.newIssueInputParameters()
iip.setSkipScreenCheck(true) //only need this if the resolution is not editable
//iip.resolutionId = null
iip.resolutionId = issue.status.statusCategory.primaryAlias == 'Done' ? '10000' : null
def result = is.validateUpdate(currentUser, issue.id, iip)
assert result.valid : result.errorCollection.errors
def updatedIssue = is.update(currentUser, result, EventDispatchOption.DO_NOT_DISPATCH, false).issue
//updatedIssue.resolutionDate = new Date().toTimestamp()
//issue.store()
//update the JIRA index so that jql for "resolved" work
//boolean wasIndexing = ImportUtils.isIndexIssues()
//ImportUtils.setIndexIssues(true)
//ComponentAccessor.getComponent(IssueIndexingService.class).reIndex(updatedIssue)
//ImportUtils.setIndexIssues(wasIndexing)
Rationale: Our small team manages multiple large Jira instances with thousands of projects, all managed by our Users/Project Admins (and not by the Jira Admins). The instances have been deliberately configured to give the Users and Project Admins as many project configuration options as possible without needing a Jira Admin. Overall, we have been very successful. Resolutions are one of our last pinch points.
Project Admins cannot manage their own Resolutions reliably without a Jira Admin needing to configure Transition Screens and Post Functions. We've worked on multiple potential solutions (user training to use Simplified Workflows, Project Automation), but still, Jira Admins are the bottleneck for Resolutions.
So we've decided that the Resolution should be set globally for all issues based on the Status Category. This way, Project Admins can passively self administer their Resolution by only using "Done" statuses when they want the Resolution to be set.
Any help configuring this functionality is greatly appreciated! If I need to go it alone, so be it. I'll post the code here for others to use.