I have a script that grabs the value of a text field, which is the user id of the user. For example the text field has a value of 432100. Before the changes for gdpr the script worked great, in fact it still works great for users that were created before the change. Now any user created after the change, the assignee field updates with the numbers but doesn't find the user. The assignee field will just have 432100 - ?. How would I fix this? Please be gentle, I don't really code :) Script below:
import com.atlassian.jira.component.ComponentAccessor
// Get required Managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get a pointer to the Implemented By user picker field and its value
def userCf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("Project Lead")
def implUser = issue.getCustomFieldValue(userCf)
// If the Implemented By Field is not null then set the assignee
if(implUser){
issue.assigneeId = implUser
}
You have to get the object that represent the user instead the user id. You can do it using userManager class.
Base on the code available here
I've create a script that I've not tested but should work. Btw, the website mention have lot of usecase you can use.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.event.type.EventDispatchOption
// Get required Managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get a pointer to the Implemented By user picker field and its value
def userCf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("Project Lead")
String implUser = issue.getCustomFieldValue(userCf)
//Dependency to save issue update
def issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
// If the Implemented By Field is not null then set the assignee
if(implUser){
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName(implUser)
if(user){
def issueInputParameters = new IssueInputParametersImpl()
issueInputParameters.setAssignee(user)
def updateValidationResult = issueService.validateUpdate(loggedInUser, issue.id, issueInputParameters)
assert updateValidationResult.valid : updateValidationResult.errorCollection
def issueUpdateResult = issueService.update(loggedInUser, updateValidationResult, EventDispatchOption.ISSUE_UPDATED, sendMail)
assert issueUpdateResult.valid : issueUpdateResult.errorCollection
}
}
Regards
I kept on getting errors from your script about the object type, but you got me going down the right path. Basically needed to turn the string into an application user. Thanks for the help. I was able to get it working with the code below:
import com.atlassian.jira.component.ComponentAccessor
// Get required Managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// get a pointer to the Implemented By user picker field and its value
def userCf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("Project Lead")
String implUser = issue.getCustomFieldValue(userCf)
//Dependency to save issue update
def issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def user = ComponentAccessor.userManager.getUserByName(implUser)
// If the Implemented By Field is not null then set the assignee
if(implUser){
issue.setAssignee(user)
}
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.