Hi Community,
I’ve setup an automation to try and populate a multi-user picker field with users that have project role: “Administrators” in said project.
I think I’m almost there. However, when the automation determines that a user with project role: “Administrators” is either a Jira group or an inactive user, it fails with error.
This failure is in the “edit field” action.
I’ll include screenshots for reference.
I’m basically sending a web request to the Jira api specifically looking at the “Administrators” role for each determined project and setting the field with “webhookResponse.xxx.xx” etc.
This worked in my test project since I only had myself and another active user with project role: "Administrators".
I believe instead of the “edit field” action, perhaps the “Execute a Scriptrunner Script” could handle these “jira group” or “inactive user” instances and only add active real users with an email attached to their account.
Would this be possible to handle with a Scriptrunner Script via automation action “Execute a Scriptrunner Script”? If so, please assist as I’m unsure how to configure such a script.
Thanks and Kind Regards,
Amed
Hi @Amed Moreno scriptrunner could do the entire automation. For that matter you could setup up a rest end point then a scripted field pulling from that endpoint to populate it within scriptrunner. Could also not just put in a validation routine (an if clause) within your automation to test for the validity of what is being returned prior to the update (edit) on the filed.
Quick question what's the end goal for the field?
Hi @Craig Nodwell ,
Thanks. The end goal of my automation is to populate a multi-user picker field for an approval process. I basically want the field to be populated with all active users in project that have role "Administrators" so that ANY of them can approve that particular step in the workflow.
Any potential solution is welcome, however, I'm very interested in knowing how I can write the script in the Automation step "Execute a Scriptrunner Script".
It needs to filter out when there is a "jira group" or inactive user with role: "Administrators" and set the field with all the active users with the project role.
Kind Regards,
Amed
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Amed Moreno I'm off work today so I don't have an environment to test on for you. However there's lots of examples you can draw off to put your script together with.
This post here from the Adaptivist Library to get all active users.
import com.atlassian.crowd.manager.directory.DirectoryManager
import com.atlassian.jira.bc.security.login.LoginService
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserFilter
import groovy.xml.MarkupBuilder
final directoryToCheck = 'Jira Internal Directory'
final groupName = 'jira-users'
def loginManager = ComponentAccessor.getComponent(LoginService)
def directoryManager = ComponentAccessor.getComponent(DirectoryManager)
def groupManager = ComponentAccessor.groupManager
def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def internalDirectoryId = directoryManager.findAllDirectories()?.find { it.name.toString().toLowerCase() == directoryToCheck.toLowerCase() }?.id
def jiraUsersGroup = groupManager.getGroup(groupName)
// Get all users that belong to JIRA Internal Directory
def allowEmptyQuery = true
def includeActive = true
def includeInactive = false
def canMatchEmail = false
def userFilter = null
def projectIds = null
def allUserParams = new UserSearchParams(allowEmptyQuery, includeActive, includeInactive, canMatchEmail, userFilter as UserFilter, projectIds as Set<Long>)
def allInternalDirectoryUsers = userSearchService.findUsers('', allUserParams).findAll { it.directoryId == internalDirectoryId }
// Get all the users that belong to JIRA Internal Directory and have never logged in
def internalDirectoryUsersNeverLoggedIn = allInternalDirectoryUsers?.findAll {
!loginManager.getLoginInfo(it.username).lastLoginTime
}
// Get all the users that belong to JIRA Internal Directory and to jira-users group
def internalUsersBelongToGroup = allInternalDirectoryUsers?.findAll { groupManager.isUserInGroup(it, jiraUsersGroup) }
// Get all the users that belong to JIRA Internal Directory and to jira-users group and have never logged in
def jiraUsersHaveNeverLoggedIn = internalDirectoryUsersNeverLoggedIn?.findAll {
groupManager.isUserInGroup(it, jiraUsersGroup)
}
def stringWriter = new StringWriter()
def content = new MarkupBuilder(stringWriter)
content.html {
p("Users in Jira Internal Directory: ${allInternalDirectoryUsers?.size()}")
p("Users in Jira Internal Directory and have never logged in: ${internalDirectoryUsersNeverLoggedIn?.size()}")
p("Users in Jira Internal Directory and in jira-users group: ${internalUsersBelongToGroup?.size()}")
p("Users in Jira Internal Directory and in jira-users group and have never logged in: ${jiraUsersHaveNeverLoggedIn?.size()}")
}
stringWriter.toString()
This Post on the community for getting all users in a Project Role.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def getUsersForSpecifiedRolesInProject(String projectName, String role){
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class)
def projectRole = projectRoleManager.getProjectRole(role)
def project = ComponentAccessor.getProjectManager().getProjectObjByName(projectName)
def usersInRole = projectRoleManager.getProjectRoleActors(projectRole, project).getApplicationUsers().toList()
return usersInRole
}
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.
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.