Conditions user in 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.
September 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.
September 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.
September 28, 2023

@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.
September 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.
September 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.
September 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.

Like Bektas Ozan Topkaya likes this
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.
September 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.
September 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