import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
//def log = Logger.getLogger("com.js.test")
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("Unassigned")
import webwork.action.ServletActionContext
def assignee = issue?.assignee
//log.debug "assignee: $assignee"
def request = ServletActionContext.getRequest()
//log.debug "request: $request"
if (request) {
def values = request.getParameterValues('assignee')
// log.debug "values: $values"
if (values && values.size() == 1) {
assignee = values[0]
// log.debug "assignee: $assignee"
}
}
if (!assignee || assignee == "-1") {
issue.assignee = user
// log.debug "Issue Assigned to Unassigned user"
}
Hi all, my code is above - it should be assigning to a dummy user, rather than the project leader...unless you specify a user specifically or use the 'assign to me' function when creating a new issue...This is the first post function in the workflow. It works for some users and not for others.
Question:
Is there some permission that is needed to access the user Manager or something?
Please advise!
Thank you
Jason
Do all users have the "Assign users" permission? If not they won't be able to set the assignee. I would assume they also need the "Browse Users" Global Permission, to be able to use the User Manager.
Hi, thanks for your reply Pete.
Unfortunately not, I didn't realise that the scripted post function relies on the user memberships. I will have to look into running the script under a technical user, do you know if that's possible? A scripted 'run as'...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this (based on admin username of "admin.user")
String adminUsername = "admin.user"
//Elevate user access to admin user
def jiraAuthenticationContext = ComponentAccessor.jiraAuthenticationContext
def adminUser = ComponentAccessor.userManager.getUserByKey(adminUsername)
def originalUser = jiraAuthenticationContext.loggedInUser
try
{
//Switch User
jiraAuthenticationContext.setLoggedInUser(adminUser)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Or of course, you could just make sure all users have the Assign Users permission...
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.