Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Problems assigning with IssueService.assign() and MutableIssue.setAssigneeId()

Tigran Shahverdyan August 27, 2015

I have a problem with this script as inline post function.

According to  after trying to set the assignee the first way nothing changes. The second way changes the assignee according to the log, but in reality .

Can anybody help with this issue?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.bc.issue.IssueService
import org.apache.log4j.Level
import org.apache.log4j.Category
 
Category log = Category.getInstance("com.onresolve.jira.groovy.ISDCreateIssuePostfunction")
UserManager userManager = ComponentAccessor.getUserManager()
IssueService issueService = ComponentAccessor.getIssueService()
log.setLevel(Level.DEBUG)
 
log.debug "Starting Postfunction..."
 
// getting current user
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
log.debug "Current user is: " + currentUser
 
// getting the issue
issueKey = issue.getKey()
MutableIssue mutableIssue = issueService.getIssue(currentUser, issueKey).getIssue()
log.debug "Current issue key is: " + mutableIssue.getKey()
log.debug "Current issue assignee is: " + mutableIssue.getAssignee()
 
userToAssign = userManager.getUserByName("t.shahverdyan")
 
log.debug "Setting user to \"" + userToAssign + "\"."
 
// validating user assign
IssueService.AssignValidationResult assignValidationResult = issueService.validateAssign(currentUser, 
							mutableIssue.getId(),
                            userToAssign.getKey());
log.debug "Validate result is: " + assignValidationResult.isValid() + ""

// assigning user. 1st way
IssueService.IssueResult issueResult = issueService.assign(currentUser, assignValidationResult)
log.debug "Assign result is: " + issueResult.isValid() + ""

// checking
log.debug "Current issue assignee is: " + mutableIssue.getAssignee()

// assigning user. 2nd way
mutableIssue.setAssigneeId(userToAssign.getKey())

// checking
log.debug "Current issue assignee is: " + mutableIssue.getAssignee()

 

log: 

screenshot after transition with script postfunction: image2015-8-28 14:39:46.png

 

UPDATE

Here is real script - . Depending on custom field (Service Type) value the assignee can be different. Also there can be no assignee. But before assigning I want to check if the person has the permission to be assigned to the issue. For that I use IssueService.validateAssign() then IssueService.assign().

UPDATE 2

Here is post functions order - .

Log from script - .

Result - .

5 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Tigran Shahverdyan October 1, 2015

@Jamie Echlin [Adaptavist] could you please help with this issue? I don't know how else to get a support on this issue.

0 votes
Guilherme Nogueira
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.
August 31, 2015

did my answer works?

0 votes
Guilherme Nogueira
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.
August 28, 2015

Try something easier:

 

P.S. put this code before those 2 default postfunction:

  1. Update change history for an issue and store the issue in the database.
  2. Re-index an issue to keep indexes in sync with the database.

 

 

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.issue.comments.CommentManager

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.util.ImportUtils

import com.atlassian.jira.user.util.UserManager

import com.atlassian.crowd.embedded.api.User

import com.atlassian.jira.component.ComponentAccessor

 

 

userManager = (UserManager) ComponentAccessor.getUserManager()

MutableIssue issue = issue

   

User NewAssignee = userManager.getUser('t.shahverdyan')

    

issue.setAssignee(NewAssignee)

 

https://answers.atlassian.com/questions/176759

 

BR.

Tigran Shahverdyan September 1, 2015

Guilherme, hi! Sorry for late answer. I just tried and it works. Thanks. But with my version I was trying to solve 2 issues: 1. assign using current JIRA API. UserManager.getUser() method is deprecated - https://docs.atlassian.com/jira/latest/com/atlassian/jira/user/util/UserManager.html#getUser(java.lang.String) 2. do all operation by checking if current user the permission to do it The problem is that I don't understand why during script session I get that the assignee is set, but in reality it is not.

Tigran Shahverdyan September 1, 2015

Also why issueService.assign() does not work, though issueResult.isValid() returns true.

Tigran Shahverdyan September 1, 2015

@Jamie Echlin [Adaptavist] , could you please help with this issue?

Guilherme Nogueira
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.
September 2, 2015

Hey, to get current user use: import com.atlassian.jira.user.ApplicationUser; ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getUser(); More info: https://developer.atlassian.com/static/javadoc/jira/reference/com/atlassian/jira/user/ApplicationUser.html Remember, you can use: User NewAssignee = userManager.getUser('t.shahverdyan')

Guilherme Nogueira
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.
September 2, 2015

Or this: User user = ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser();

Guilherme Nogueira
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.
September 2, 2015

Hope it help :)

Guilherme Nogueira
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.
September 2, 2015

I forgot two things: "2. do all operation by checking if current user the permission to do it" - You can control it by workflow validator, it's easier . "Also why issueService.assign() does not work, though issueResult.isValid() returns true. " I have no idea at all

Guilherme Nogueira
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.
September 2, 2015

Please accept my answer if it worked :)

Tigran Shahverdyan September 3, 2015

Guilherme, I know how to get the current user. It is in my code above. About the operation checking. The validator will not work as my real script has switch operator in it and in some cases it doesn't assign at all. I already answered you about getUser() method. I'll edit my original question. Thanks anyway.

JamieA
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.
October 1, 2015

What's your real script? Slim it down to the simplest possible case and post it.

Tigran Shahverdyan October 2, 2015

I posted an update in original post. Thanks!

JamieA
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.
October 4, 2015

And that doesn't work? What position does it have in the list of post-functions?

Tigran Shahverdyan October 6, 2015

Yes. I added Update 2.

Tigran Shahverdyan October 26, 2015

@Jamie Echlin [Adaptavist] I posted the answers. Could you please look into it?

JamieA
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.
October 28, 2015

Make it last in the list and it will work.

0 votes
Tigran Shahverdyan August 28, 2015

Updated the post with log and screenshot.

0 votes
Guilherme Nogueira
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.
August 27, 2015

Can you put your error log here?

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events