Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
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

Conditions user in group

Edited
Alex
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.
Sep 28, 2023

Hi,everyone!

Please tell me how can I make the script work? Condition: if the current user is a member of one of the groups, then true, otherwise false. I'm new to groove and my skipp doesn't work yet

 

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def groupManager = ComponentAccessor.getGroupManager()

def groupName = ["adm", "jira-administrators"]

if(groupManager.getGroupNamesForUser(currentUser).containsAll(groupName.any()) ){

true

}

else {

false

}

1 answer

1 accepted

1 vote
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 28, 2023

Hi @Alex  Are you using Jira Cloud or Jira Server/DC ? I am asking this because you tagged jira-cloud but using jira server scriptrunner groovy code. 

If you're using Jira Cloud, Jira expression language works in scripted workflow condition.

https://docs.adaptavist.com/sr4jc/latest/features/workflow-extensions/jira-expression-examples

 user.groups.includes('usergroup')
Alex
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.
Sep 28, 2023 • edited

@Vikrant Yadav  Hi!
My version - server.
Script needed for this automation(hide ui element)\


 

Alex
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.
Sep 28, 2023

sc.png

Alex
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.
Sep 28, 2023

@Vikrant Yadav I can't figure out how to fix it so it works.. Could you highlight it if I missed something in it? Thank you

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 28, 2023

@Alex  Try below script :- 

 

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

return ComponentAccessor.getGroupManager().isUserInGroup(currentUser,"jira-administrators") || ComponentAccessor.getGroupManager().isUserInGroup(currentUser,"jira-users")

 

The provided script is checking if the currently logged-in user is a member of either the "jira-admin" group or the "jira-users" group in Jira using the OR (||) logical operator. Here's a breakdown of what the script does:

It gets the currently logged-in user using ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() and assigns it to the currentUser variable.

It checks if the currentUser is a member of the "jira-admin" group using ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "jira-admin"). If the user is a member of this group, this part of the condition evaluates to true.

It checks if the currentUser is a member of the "jira-users" group using ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "jira-users"). If the user is a member of this group, this part of the condition evaluates to true.

The || operator between the two checks means "OR," so if either of the two conditions (user in "jira-admin" or user in "jira-users") evaluates to true, the entire condition will be true.

Finally, the script returns the result of this condition, which will be true if the user is in either of the specified groups, and false if the user is not in either group.

In summary, this script is checking if the currently logged-in user is in either the "jira-admin" or "jira-users" group and returns true if the user is in either of these groups and false if the user is not in either group.

Alex
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.
Sep 28, 2023

@Vikrant Yadav 

Thanks a lot ! This works great!

Like Vikrant Yadav likes this
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 28, 2023

You're Welcome :)

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events