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,560,360
Community Members
 
Community Events
185
Community Groups

if reporter is member of a group get a custom field

Hello , 

I need your help with Groovy please !

I have the following scenario : 

" if reporter is member of group "JIRA_VIP" , then get custom field" Category " as VIP " 

to get the custom field , I use the postfunction to set the field value function in a transition (using nFeed ) .

 

I have tried this code but without success ! 

1 ) ------------------------------------------------------

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

currentUser == issue.reporter
def groupManager = ComponentAccessor.getGroupManager()
if (groupManager.isUserInGroup(issue.reporter?.name, 'JIRA_VIP'))
getCustomFieldValue("customfield_11203")

2) ----------------------------------------------------------

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


def groupManager = ComponentAccessor.getGroupManager()
groupManager.isUserInGroup(issue.reporter?.name, 'JIRA_VIP')

3) -----------------------------------------------------------------

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

def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Category")
def value = issue.getCustomFieldValue(field)
def groupManager = ComponentAccessor.getGroupManager()
if (groupManager.isUserInGroup(issue.reporter?.name, 'JIRA_VIP'))
getCustomFieldValue("customfield_11203")

 

3 answers

Hello I found a solution for this. May be you can use this script:

 

"

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserManager();
def groupManager = ComponentAccessor.getGroupManager()

if(groupManager.isUserInGroup(issue.getReporter(), 'JIRA_VIP'))
{
def cField = customFieldManager.getCustomFieldObject("BBB")
def cFieldValue = issue.getCustomFieldValue(cField)
issue.setFieldValue("AAA",cFieldValue);
} elseif (groupManager.isUserInGroup(issue.getReporter(), 'Normal User'))
{
def cField = customFieldManager.getCustomFieldObject("CCC")
def cFieldValue = issue.getCustomFieldValue(cField)
issue.setFieldValue("AAA",cFieldValue);

.....

"

 

But first create a customfields like ;

AAA -> Category = ( VIP, Normal User, Vendor etc.)  

BBB ->Category1 = VIP

CCC -> Category2 = Normal User

 

and set this fields hidden in the request type; You can show the field AAA to seen from everyone.

Run your script above; if user in VIP group get customfield number Category1 and parse it to general Category customfield.

if user in Normal User group get customfield number Category2 and parse it to general Category custom field.

Hello I have a same problem with your issue.

I have set a custom field at the request type fields. And the field is hidden, 

Every request type has a hidden help desk group. 

I want to make a chooser ; If current reporter "user" opens a ticket my groovy script will find which group the user belongs to. And set the proper help desk group automatically. 

But I am confuced. How to this?

Here is my script

import com.atlassian.jira.component.ComponentAccessor

def groupDGP = ComponentAccessor.groupManager.getGroup("33-Doğal Gaz İşletme ve Piyasa İşlemleri Bölge Müdürlüğü")
if(ComponentAccessor.groupManager.getUserNamesInGroup(groupDGP).contains(currentUser)){
issue.get("customfield_10228")==issue.get("customfield_10503")
}

Hey, 

Did you manage with this. I am trying to do the same thing... if a user is a member of a VIP group, switch the VIP button on.

Dan

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events