You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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:
The same appeared for def customFieldManager = ComponentAccessor.getCustomFieldManager()
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:
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.