Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted field vs. behaviours vs. listeners

David J March 6, 2018

Hello all,

I want to set a custom field of type "single select"'s value on the event of a user being assigned, and by determining the user's group membership.

Say user A belongs to group "Product Management". Upon someone assigning an issue to him, I want to set custom field B (single select) to the existing option "Product Management".

As a first step I've succeeded doing this with a ScriptRunner custom field of type Script Field containing following code:

import com.atlassian.jira.component.ComponentAccessor

def user = issue.assignee

if (user) {

             def userUtil = ComponentAccessor.getUserUtil()

               

    if (userUtil.getGroupNamesForUser(user.name).contains("PM")) {

        return "TEST Product Management"

    } else {

        return "Error - User not in defined group"

    }    

} else {

return ""

}

It successfully returns the group name as a string.

But now I want, but I am failing, to translate the same into something that makes use of the existing custom field of type single select, where there is no obvious way to apply a script.

I've read about the behaviour plugin and listeners and tried behaviours but getting specific errors on using userUtil.getGroupNamesForUser(user.name).contains("PM") in the inline script.

Can anyone please point me in the right direction, or provide some snippet to set respective values?

Thank you!

David

1 answer

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 6, 2018

Where you've used user.name, you probably need user.getUsername() (or possibly user.getDisplayName(), but I think it's the login you want, not the display name)

David J March 9, 2018

Thanks.

Suggest an answer

Log in or Sign up to answer