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
I have the following ScriptRunner behaviour script for our "Required Reviewers" multiuser custom field:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.UserPropertyManager
import com.atlassian.jira.issue.IssueManager
class SetRequiredReviewers extends com.onresolve.jira.groovy.user.FieldBehaviours
{
def run()
{
IssueManager issueManager = ComponentAccessor.getIssueManager();
def mutableIssue = issueManager.getIssueObject(underlyingIssue.id)
def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
List<ApplicationUser> reviewMembers = groupManager.getUsersInGroup("Review Board Member")
def reqRevField = customFieldManager.getCustomFieldObjectByName("Required Reviewers")
mutableIssue.setCustomFieldValue(reqRevField, reviewMembers)
}
}
However, it never populates, even though if I do some log debug statements, the users I currently have in the Review Board Member group are being found. There's no errors, either.
I also tried adding just a list of user names, but that didn't work, either.
What am I doing wrong here?
Thanks!
Try like this
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.UserPropertyManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
class SetRequiredReviewers extends com.onresolve.jira.groovy.user.FieldBehaviours
{
def run()
{
IssueManager issueManager = ComponentAccessor.getIssueManager();
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def mutableIssue = issueManager.getIssueObject(underlyingIssue.id)
def groupManager = ComponentAccessor.getGroupManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
List<ApplicationUser> reviewMembers = groupManager.getUsersInGroup("Review Board Member")
def reqRevField = customFieldManager.getCustomFieldObjectByName("Required Reviewers")
mutableIssue.setCustomFieldValue(reqRevField, reviewMembers)
ComponentAccessor.getIssueManager().updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
}
}
Thanks for the response!
I'm trying to populate the field on screen launch. Basically pre-populate the field for the user with default users pulled from the Review Board Member group. So while that works, I have to go back into that state transition to see the update, and then continue with the flow.
If there was a way to set the default users in a multiuser select field to a group, instead of having to add individual users as default, that would be ideal. Unfortunately I don't see a way to do that so I was using a behaviour. Is there a better way?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are not using behaviours the right way. You should set values with setFormValue method.
https://scriptrunner.adaptavist.com/latest/jira/behaviours-api-quickref.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I had tried that previously (all my other behaviors use the normal api and work fine), but all I get in the multiuser field is [object Object] when call reqField.setFormValue(reviewMembers).
So perhaps I'm just not passing the correct list of values. I'll mess around with it more. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah yup that was my problem. I was passing in the list of ApplicationUser and apparently via a Behaviour you have to pass in an array of user name Strings. Got it! THank you for the help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am glad you solved the problem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jason Adam Can you share your script for updating the multi user select field. I can't seem to get this to work.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def usersField = ComponentAccessor.customFieldManager.customFieldObjects.findByName("User(s)")
String[] users = ["boisvers"]
usersField.setFormValue(users)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Figured it out, you have to use getFieldByName for service desk/management forms:
def usersField = getFieldByName("User(s)")
usersField.setFormValue(["boisvers"])
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jason,
could you please tell me how exactly did you solve this problem?
I am trying to achieve a similar thing. I want to pre populate a mult userpicker field with values from the same field of the parent issue. I tried a lot of approaches with arrays but just couldn't get it to work...
Here is my script so far:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
def UserManager = ComponentAccessor.getUserManager()
def parent = getFieldById("parentIssueId")
Long parentIssueId = parent.getFormValue() as Long
def issueManager = ComponentAccessor.getIssueManager()
def parentIssue = issueManager.getIssueObject(parentIssueId)
//Parent
def teilnehmerField = customFieldManager.getCustomFieldObject(11400)
def parentValue = parentIssue.getCustomFieldValue(teilnehmerField).toString()
//Child
def teilnehmer = getFieldById("customfield_11400")
teilnehmer.setFormValue(parentValue)
I am only getting "[hessling(hessling)" pre populated in the multi user picker field, but not the usernames...
Many thanks in advance
Daphnis
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.