Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner Groovy Script - Set summary based on custom fields in WF post-function in Jira 8

Hi,

I'm trying to set the summary in a WF post-function based on selections of the issue type and a single-user-picker custom field.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

MutableIssue issue = issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def vIssueType = issue.getIssueType().name
def vUserPickerCF = customFieldManager.getCustomFieldObjectByName("myUserPickerCF")
def vUser = issue.getCustomFieldValue(vUserPickerCF) as ApplicationUser

issue.setSummary("[" + vIssueType + "] " + vUser.displayName + " (" + vUser.username + ")");

 The script worked in Jira 7, but while testing Jira 8 the following warnings were raised:

1.pngThe same appeared for def customFieldManager = ComponentAccessor.getCustomFieldManager()
2.png

So I corrected them all and ended up with

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

MutableIssue mutableIssue = issue
def cfManager= ComponentAccessor.getCustomFieldManager()

def vIssueType = issue.getIssueType().name
def vUserPickerCF = cfManager.getCustomFieldObjectsByName("myUserPickerCF")
def vUser = issue.getCustomFieldValue(vUserPickerCF) as ApplicationUser

issue.setSummary("[" + vIssueType + "] " + vUser.displayName + " (" + vUser.username + ")");

And now this error appears:

3.png

I tried to replace "issue." with "mutableIssue." but that doesnt work either, same error.

How should this code look like when upgrading to Jira 8? Is there maybe a simpler way of achieving this?

Thanks & Cheers, Tom

1 answer

0 votes

Hello, 

It seems like you have multiple CFs with this name or maybe the function returns a Collection by default now. That's why I usually use ids but if you use get(n) (n beeing the index of the correct cf) you should be able to fetch your cf. 

cfManager.getCustomFieldObjectsByName("myUserPickerCF")

 

And you are using issue and mutableIssue, you should stick with mutableIssue.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

MutableIssue mutableIssue = issue
def cfManager= ComponentAccessor.getCustomFieldManager()

def vIssueType = mutableIssue.getIssueType().name
def vUserPickerCF = cfManager.getCustomFieldObjectsByName("myUserPickerCF")
def vUser = mutableIssue.getCustomFieldValue(vUserPickerCF) as ApplicationUser

mutableIssue.setSummary("[" + vIssueType + "] " + vUser.displayName + " (" + vUser.username + ")");

Even if you can get the info from a issue, with a mutableIssue you can get and set so mixing them up is not necessary and makes the code less readable in my opinion.

Hope that helped,

Cheers 

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

⚡️NEW Group for Confluence Cloud Admins

Calling all Confluence Cloud Admins!  We created a new Community Group to support your unique needs as Confluence admins. This is a group where you can ask questions, access resou...

116 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you