How to update issue and set assignee?

Daniel Micallef April 15, 2016

I want to update an existing JIRA Issue and set a new value for the assignee. Up till now I have managed to update issue status with the following:

issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_ASSIGNED, false);

I also managed to update the description via IssueInputParameters, however using the same method the Assignee is never assigned.

issueInputParameters.setAssigneeId(userManager.getUserByName("admin-daniel").getKey())
	.setDescription("I am the issue description.4");

The Description is set however the Assignee remains unassigned via this method. Any ideas as to why this may be happening?

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Ahm CHA July 15, 2016
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
 
LOG.error("Updating Issue.");
//Setting Issue Input Parameters
issueInputParameters.setAssigneeId(userManager.getUserByName("admin-daniel").getName());
 
//Validating Update
IssueService.validateAssign(userManager.getUserByName("admin-daniel"),currentIssue.getId(),userManager.getUserByName("admin-daniel").getName());
1 vote
J.Fawkes April 21, 2016

Hi,

Try use issueInputParameters.setAssigneeId(userManager.getUserByName("admin-daniel").getName())

setAssigneeId() method takes username as parameter:
issueInputParameters.setAssigneeId(user.getName()); 

Daniel Micallef April 22, 2016

Hi J.Fawkes,

Thanks for your answer. However the user remained unassigned, as per the image below:

image2016-4-22 17:47:34.png

 

On the other hand, the description was set. The code is as per below.

 

IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

LOG.error("Updating Issue.");
//Setting Issue Input Parameters
issueInputParameters.setAssigneeId(userManager.getUserByName("admin-daniel").getName())
    .setDescription("User Name: " + userManager.getUserByName("admin-daniel").getName());

//Validating Update
IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(user, issue.getId(), issueInputParameters);
if(updateValidationResult.isValid()) {
    IssueResult updateResult = issueService.update(user, updateValidationResult);
    LOG.error("Update Result Done without error. Assignee is " + updateResult.getIssue().getAssignee().getDisplayName());
}else{
    LOG.error("Update Validation Result not Valid.");
}
Daniel Micallef April 25, 2016

I ended up solving the problem by scrapping IssueInputParameters in favor of the following:

MutableIssue mutableIssue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(issue.getKey());
mutableIssue.setAssignee(user);
IssueManager issueManager = ComponentAccessor.getIssueManager();
issueManager.updateIssue(user, mutableIssue,EventDispatchOption.ISSUE_ASSIGNED, true);

 

 

Like ABRAR ALMADI likes this
Yagnesh Bhat
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.
May 10, 2016

Hi, @Daniel Micallef, even I am facing the same problem - I tried your solution but still its not setting the assignee. Is there anything more to the above code , by any chance?

Update : I see the assignee being updated in issue history but NOT on the screen. Is there anything I am missing?

Daniel Micallef May 10, 2016

Hi @Yagnesh Bhat, this was done using JIRA 6.3;

I think you should check if any changes were made for your version of JIRA, maybe the type of user (ApplicationUser or simply User). Also make sure that you are using MutableIssue.

Yagnesh Bhat
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.
May 11, 2016

Thanks for the update Daniel, its now working 

Raj April 15, 2019

@Yagnesh Bhat , Can i have the detailed code used for updating an assignee automatically in an issue using ScriptRunner.

Yagnesh Bhat
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.
April 16, 2019

@Raj , its been quite a while I got that working, however, I just saw the answer provided by @Ahm CHA below this one - I think that should work. Basically you set the assignee id through issueinput parameters :

https://docs.atlassian.com/software/jira/docs/api/7.6.1/index.html?com/atlassian/jira/issue/IssueInputParameters.html

 

And then validate the assign transition using the issue service method:

https://docs.atlassian.com/software/jira/docs/api/7.2.1/com/atlassian/jira/bc/issue/IssueService.html#validateAssign-com.atlassian.jira.user.ApplicationUser-java.lang.Long-java.lang.String-

 

For more info about using the issue service and how it works, please refer to this awesome documentation by Atlassian:

https://developer.atlassian.com/server/jira/platform/performing-issue-operations/

 

Hope this helps.

Like Raj likes this
Raj April 16, 2019

Thanks @Yagnesh Bhat for your recommendations.

i have got the required script.

TAGS
AUG Leaders

Atlassian Community Events