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.jqlimport com.atlassian.jira.JiraDataTypeimport com.atlassian.jira.JiraDataTypesimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.jql.operand.QueryLiteralimport com.atlassian.jira.jql.query.QueryCreationContextimport com.atlassian.jira.permission.ProjectPermissionsimport com.atlassian.jira.project.version.VersionManagerimport com.atlassian.query.clause.TerminalClauseimport com.atlassian.query.operand.FunctionOperandclass 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.jqlimport com.atlassian.jira.JiraDataTypeimport com.atlassian.jira.JiraDataTypesimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.jql.operand.QueryLiteralimport com.atlassian.jira.jql.query.QueryCreationContextimport com.atlassian.jira.project.version.VersionManagerimport com.atlassian.query.clause.TerminalClauseimport com.atlassian.query.operand.FunctionOperandclass 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.
Hi @David Harkins
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
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
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?
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.
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.jqlimport com.atlassian.jira.JiraDataTypeimport com.atlassian.jira.JiraDataTypesimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.jql.operand.QueryLiteralimport com.atlassian.jira.jql.query.QueryCreationContextimport com.atlassian.jira.project.version.VersionManagerimport com.atlassian.query.clause.TerminalClauseimport com.atlassian.query.operand.FunctionOperandclass 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) } }}
It looks like you're new here. Sign in or register to get started.