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
Hi Radek,
Thanks for valuable suggestion and I tried with the above code and stuck with syntax error in closing "}"
Please help if the below snippet is correct.
Hi All,
I am able to resolve the syntax error but stuck at updating the issue with the below error.
[Static type checking] - The variable [EventDispatchOption] is undeclared.
It seems to be that the error is that the variable EventDispatchOption is undeclared in the program but not sure where to declare the variable in the program to fix the issue.
The error is at the below line and I am running the code on the script runner 7.11.
I have tried to added the import utility "import com.atlassian.jira.event.type.EventDispatchOption" but still doesn't help to resolve the issue
Below is the full code I am trying to update the fix version value in a specific project.
Kindly help me to resolve the issue.
Thanks,
Ramesh
***********************************************************************************