Trying to get the following custom JQL Function working in data center.
To compare a custom field and check if its group value is in the list of groups that the current user is a member of.
package com.onresolve.jira.groovy.jql
import com.atlassian.jira.JiraDataType
import com.atlassian.jira.JiraDataTypes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.permission.ProjectPermissions
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
class AssignedToMyGroups extends AbstractScriptedJqlFunction implements JqlFunction {
def versionManager = ComponentAccessor.getComponent(VersionManager)
def permissionManager = ComponentAccessor.getPermissionManager()
@Override
String getDescription() {
"Issues where Group field is one of My Groups"
}
@Override
List<Map> getArguments() {
Collections.EMPTY_LIST // <1>
}
@Override
String getFunctionName() {
"AssignedToMyGroups"
}
@Override
JiraDataType getDataType() {
JiraDataTypes.VERSION // <2>
}
def groupManager = ComponentAccessor.groupManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
final username = loggedInUser.username
@Override
List<QueryLiteral> getValues(
groupManager.getGroupNamesForUser(username)
)
}
Made some progress, Now showing up in the Scriptrunner JQL Functions, but not having the desired effect.
package com.onresolve.jira.groovy.jql
import com.atlassian.jira.JiraDataType
import com.atlassian.jira.JiraDataTypes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
class AssignedToMyGroups extends AbstractScriptedJqlFunction implements JqlFunction {
def versionManager = ComponentAccessor.getComponent(VersionManager)
def permissionManager = ComponentAccessor.getPermissionManager()
@Override
String getDescription() {
"Issues where Group Custom Field is one of the Current Users Group"
}
@Override
List<Map> getArguments() {
Collections.EMPTY_LIST // <1>
}
@Override
String getFunctionName() {
"AssignedToMyGroups"
}
@Override
JiraDataType getDataType() {
ArrayList // <2>
}
@Override
List<QueryLiteral> getValues(
QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause
) {
def groupManager = ComponentAccessor.groupManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def username = loggedInUser.username
def groups = groupManager.getGroupNamesForUser(username) as ArrayList
return groups
}
}
The purpose is to return all the groups that the current user is a member of so that a Single Group Custom field can be checked to confirm if it is in the list of groups.
So, after some digging around and research, I have a working version now :-)
I located a comment on a similar topic by @JamieA, which let me to GitHub and the following JQL Function which gave me my missing pieces. CurrentTeams.groovy · GitHub
My final code is:
package com.onresolve.jira.groovy.jql
import com.atlassian.jira.JiraDataType
import com.atlassian.jira.JiraDataTypes
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
class groupsOfCurrentUser extends AbstractScriptedJqlFunction implements JqlFunction {
def versionManager = ComponentAccessor.getComponent(VersionManager)
def permissionManager = ComponentAccessor.getPermissionManager()
@Override
String getDescription() {
"Get Current Users Groups"
}
@Override
List<Map> getArguments() {
Collections.EMPTY_LIST
}
List<String> getGroups() {
def groupManager = ComponentAccessor.groupManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def username = loggedInUser.username
def groups = groupManager.getGroupNamesForUser(username) as ArrayList
groups
}
@Override
JiraDataType getDataType() {
JiraDataTypes.TEXT
}
@Override
String getFunctionName() {
"groupsOfCurrentUser"
}
@Override
List<QueryLiteral> getValues(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause
) {
getGroups().collect{
new QueryLiteral(operand, it)
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you provide more information on what exactly you are trying to do?
What type of custom field are you using? Is it a group picker or a user picker? I am requesting this information to try to provide a sample code.
I am looking forward to your feedback.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_
Thank you for taking the time to reply :-)
The Custom Field that will be used is a Group Picker (Single Group)
This will then allow us to better associated / assign issue to a group of agents that have the respective skills based on group membership.
Many Thanks
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for providing the information.
I have a couple of questions to ask, i.e. what approach do you want to use to assign the issue, i.e. Post-Function, Listener or Behaviour?
Secondly, since you are taking this by groups, the Assignee field can only add one person at a time. What other conditions do you intend to use to filter out the most appropriate person from the group to assign the issue to?
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_
The value of the 'Assignee Group' custom field will be populated by listeners and a combination of defined class methods.
What we are trying to do here is create a filter to show all issues where the current user is a member of the group name that is in the 'Assignee Group'
Agents can then see all issues that they have the skills to progress, they can then assign the issues to themselves. But still remain with the group to handle agent working hours and vacations for 24/7 coverage.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Going through your latest comment, this is not doable.
You can restrict the Issue Type by Role or Group visibility during the Create / Edit / Transition screen using ScriptRunner's Behaviour.
However, once the issue is created, all users can view it on the view screen.
A similar question was asked in this Community Post.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ram Kumar Aravindakshan _Adaptavist_
Maybe I've not explained myself very well, or over explained.
One Custom Field on the issue. How it gets populated is already handled.
The reason for this custom scriptrunner JQL is to return issues where the current user is a member of the single group that is in the custom field.
Yes, all agents can view all issues in the project, this JQL will allows queues and dashboards to be created that are specific for the currents users skill set.
If the above code returns all the groups that the current user is a member of,
then if the group in the custom field is in the returned list, the issue will be returned in the JQL output.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you catch the news at Team ‘25? With Loom, Confluence, Atlassian Intelligence, & even Jira 👀, you won’t have to worry about taking meeting notes again… unless you want to. Join us to explore the beta & discover a new way to boost meeting productivity.
Register today!Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.