Dear All,
I am trying to schedule a script via script runner to update the fixversion field in the specified format with the help of listners.
I used the below groovy script
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.project.version.VersionManager
def versionNameFormat = /^Version-\d+$/ // Customize the version name format here
// Get the version manager component
VersionManager versionManager = ComponentAccessor.getVersionManager()
// Get the issue and project from the event
Issue issue = event.issue
def project = issue.getProjectObject()
// Check if the project matches the desired format
if (project.key == "YOUR_PROJECT_KEY") {
// Get or create the fix version with the desired format
Version fixVersion = versionManager.getByProjectAndName(project, "Version-1")
if (!fixVersion) {
fixVersion = versionManager.createVersion(project.id, "Version-1", "")
}
// Add the fix version to the issue
MutableIssue mutableIssue = issue as MutableIssue
mutableIssue.fixVersions = [fixVersion]
// Update the issue and re-index it
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
// Log a message to the Jira log
log.info("Fix version 'Version-1' added to issue ${issue.key}")
}
I am getting an error [[Static type checking] - Cannot find matching method com.atlassian.jira.project.version.VersionManager#createVersion(java.lang.Long, java.lang.String).] in the routines "getByProjectAndName" and "createVersion" of the version.
Version fixVersion = versionManager.getByProjectAndName(project, "Version-1")
if (!fixVersion) {
fixVersion = versionManager.createVersion(project.id, "Version-1", "")
It would be great any other alternate routines to resolve the errors to resolve my purpose.
Thanks and Regards,
Ramesh Penuballi