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,463,682
Community Members
 
Community Events
176
Community Groups

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

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

Atlassian Community Events