Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,552,061
Community Members
 
Community Events
184
Community Groups

Scriptrunner Listener: Edit Version Description upon creation of Version

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)
1) How do I get the id of the Version that was created with the event I'm listening for/to? And then insert that as the Version to be updated with editVersionDetails?
2) None of the content I've put in the parenthesis for editVersionDetails has worked, I always get an error. Even when hardcoding an existing Version ID and an existing Version Name like so:
ComponentAccessor.versionManager.editVersionDetails(80641, VB1, "Approver: ____ Tester: _____")
I get this error result
groovy.lang.MissingPropertyException: No such property: VB1 for class: Script1402 at Script1402.run(Script1402.groovy:3)

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 08, 2022

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
}
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 12, 2022

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)
Like Virginia Byrne likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events