Objective: Upon VersionCreateEvent, automatically edit created Version to have the template text "Approver: ____ Tester: ____" in the Version Description.
This should be so simple, and I'm clearly missing something. When a version is created for the "TST" project, I want to update the Version Description text to "Approver: ____ Tester: ____". I am looking to use a Listener, although if there's a better way I'm open to it.
I started with the Create a New Fix Version of the Selected Project from Adaptivist Library, as well as the editVersionDetails method from the VersionManager of the API reference. Looking to cobble it together, I have the very basic (and very non-compiling) Listener of:
import com.atlassian.jira.component.ComponentAccessor
// the key of the project under which the version will be edited
final String projectKey = "TST"
// the name of the version just created, also incorrect
final String versionName = $createdVersion
// a description for the new version
final String reldesc = "Approver: _____ Tester: _____ "
ComponentAccessor.versionManager.editVersionDetails($createdVersion, ????, reldesc)
ComponentAccessor.versionManager.editVersionDetails(80641, VB1, "Approver: ____ Tester: _____")
groovy.lang.MissingPropertyException: No such property: VB1 for class: Script1402 at Script1402.run(Script1402.groovy:3)
The event variable that will be available within the context of your event listener when listening for Version Create Event will be of type VersionCreateEvent.
And one of the available method for that class are "getVersion" and getVersionId.
So in your groovy script, you can call event.version.id or event.versionId
You might also want to consult event.version.description and possibly use the user-submitted description in your template.
Something like this:
import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.versionManager
def version = event.version
def descriptionTemplate = 'Approver: _____ Tester: _____ '
def newDescription =descriptionTemplate
if(version.description){
newDescription = descriptionTemplate + '\n' + version.description
}
versionManager.editVersionDetails(version, version.name, newDescription)
Thank you @Peter-Dave Sheehan, much appreciate the quick response. This does the trick.
Want to check my slowly evolving groovy knowledge here...the if statement at the end is to take into account if the user creating the version puts text in the Description field (or doesn't), yes? If I wanted my template text in the Description to overwrite anything the user enters, I could remove the following and drop the newDescription variable entirely?
if(version.description){
newDescription = descriptionTemplate + '\n' + version.description
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Correct, if you don't care what the user enters and you just want to overwrite it, you could just use:
import com.atlassian.jira.component.ComponentAccessor
def versionManager = ComponentAccessor.versionManager
def version = event.version
def descriptionTemplate = 'Approver: _____ Tester: _____ '
versionManager.editVersionDetails(version, version.name, descriptionTemplate)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.