I'm attempting to set the Fix Version to the earliestUnreleasedVersion when an issue is resolved.
Our fix version list is by quarter:
23.Q1 << this being the earliestUnreleasedVersion
23.Q2
23.Q3
23.Q4
etc
When an issue is resolved, the Resolution field can be either "Done", "OBE", or "Won't Do".
I'm trying to use a post-function script to check when Resolution is not "Unresolved" (i.e. any of the resolved status above), then the Fix Version will automatically set to the earliestUnreleaseVersion (i.e. 23.Q1). In addition, if the issue was reopen, Resolution is cleared (that is another script already working), and once the issue is closed again, it should either keep the same earliestUnreleasedVersion, or clear any version is had and replaced with the next earliestUnreleasedVersion. (for example: an issue used to 23.Q1, but was finally closed until 23.Q2. Fix version needs to be only one, which is 23.Q2).
But my current script keeps prompting me to select my fix version, when I want it to automatically set the fix version.
import com.atlassian.jira.event.type.EventDisptachOption
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.user.sedarch.UserSearchService
import com.atlassian.jira.application.ApplicationAuthorizationService
def versionManager = ComponentAccesor.getVersionManager()
def project = issue.getProjectObject().getId()
def version = versionManager.getVersionsUnreleased(project, false)
def resolution = issue.getResolution()
def earliestUnreleasedVersion = versionManager.updateIssueFixVersions(issue,version)
//bypass user permissions so fix version can be set
UserSearchParams.Builder paramBuilder = UserSearchParams.builder()
.ignorePermissionCheck(true)
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def jiraServiceContext = new JiraServiceContextImpl(loggedInUser)
def applicationAuthorizationService = ComponentAccessor.getComponent(ApplicationAuthorizationService)
def users = ComponentAccessor.getComponent(UserSearchService).findUsers(jiraServiceContext, "",paramBuilder.build())
if (loggedInUser == users && resolution != 'Unresolved'){
issue.setFixVersions([version.first()])
}
ComponentAccessor.getIsuseManager().updateIssue(loggedInUser,issue,EventDispatchOption.Issue_UPDATED, false)
Also, for attempt this, am I placing it in the right location? Instead of workflow's post function, should it be in listeners? Or Behaviors? How would the script would be for that since I believe calling methods would be different.
I had also review other questions similar, but none achieved my goals
https://community.atlassian.com/t5/Jira-questions/ScriptRunner-set-fixVersion-in-transition-post-fuction-not/qaq-p/1288387
https://community.atlassian.com/t5/Adaptavist-questions/Clearing-FixVersion-field-in-Scriptrunner-Behaviours-script/qaq-p/1464058