Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Jason Jellyfish
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 9, 2019
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

0 votes
Pete Singleton
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 9, 2019

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.

Jason Jellyfish
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 10, 2019

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

Pete Singleton
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 10, 2019

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
Pete Singleton
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 10, 2019

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