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
}
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')
@Vikrant Yadav Hi!
My version - server.
Script needed for this automation(hide ui element)\
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.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot ! This works great!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're Welcome :)
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.