It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scripted Post Function only working for certain users...please advise

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 

1 answer

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'...

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)
}
Like Jason Jellyfish likes this

Or of course, you could just make sure all users have the Assign Users permission...

Like Jason Jellyfish likes this

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you