Hello,
I am trying to develop a post function that shall assign the issue to the currently logged-in user, if a condition is met.
I am able to fetch the current logged-in user using below:
// Get the current logged in user
def user = ComponentAccessor.getJiraAuthenticationContext().getUser().getName()
Now, I have to assign the issue to this user. For that, I am trying
issue.setAssigneeId(user)
However, it is resulting "null" and issue remains unassigned.
Can anyone please let me know, what I am missing and how I can achieve it?
Thanks.
Nishant
Your code should be like this
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setAssigneeId(user)
I tried it..It is giving below error:
No signature of method: com.atlassian.jira.issue.IssueImpl.setAssigneeId() is applicable for argument types: (com.atlassian.jira.user.BridgedDirectoryUser) values: [Nishant.Kansal@abc.com:10001] Possible solutions: setAssigneeId(java.lang.String), getAssigneeId(), setAssignee(com.atlassian.crowd.embedded.api.User), getAssignee()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setAssignee(user)
What is your Jira version?
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.
Did the lines in my previous comment work? In Jira version 6 there were problems with ApplicationUser and User classes. Some methods worked with ApplicationUser and some with User and those classes always had to be converted to each other. Kindly try the lines in my previous comment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, it didn't work.
I checked few other scripts available in this forum and a validation need to be in place. Can you please guide me on the same?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is the error?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
After going through couple of articles, I worked out below script. It seems, I am so near and yet not able to get it through.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.event.type.EventDispatchOption
//import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.UpdateIssueRequest
import org.apache.log4j.Level
import org.apache.log4j.Logger
def LOG = Logger.getLogger("com.onresolve.jira.groovy")
LOG.error("Updating Issue.");
def user = ComponentAccessor.getJiraAuthenticationContext().getUser().getName()
MutableIssue updatedIssue = ComponentAccessor.getIssueManager().getIssueObject(currentIssue.getKey())
updatedIssue.setAssigneeId(user)
IssueManager issueManager = ComponentAccessor.getIssueManager();
issueManager.updateIssue(user, updatedIssue, EventDispatchOption.ISSUE_UPDATED, true)
It is giving me below error:
No signature of method: com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue() is applicable for argument types: (java.lang.String, com.atlassian.jira.issue.IssueImpl, com.atlassian.jira.event.type.EventDispatchOption$EventDispatchOptionImpl, java.lang.Boolean).
Possible solutions: updateIssue(com.atlassian.crowd.embedded.api.User, com.atlassian.jira.issue.MutableIssue, com.atlassian.jira.event.type.EventDispatchOption, boolean), updateIssue(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.MutableIssue, com.atlassian.jira.issue.UpdateIssueRequest)
Tried the possible solutions, however, no success.
Please help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is because your user variable is a String and you need to pass com.atlassian.jira.user.ApplicationUser. That is why I rewrote it like this
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setAssignee(user)
If you do not want to change your code much than it could be like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.event.type.EventDispatchOption
//import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.UpdateIssueRequest
import org.apache.log4j.Level
import org.apache.log4j.Logger
def LOG = Logger.getLogger("com.onresolve.jira.groovy")
LOG.error("Updating Issue.");
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
MutableIssue updatedIssue = ComponentAccessor.getIssueManager().getIssueObject(currentIssue.getKey())
updatedIssue.setAssigneeId(user.getName())
IssueManager issueManager = ComponentAccessor.getIssueManager();
issueManager.updateIssue(user, updatedIssue, EventDispatchOption.ISSUE_UPDATED, true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you, Alexey for pointing out the mistake in my latest code. It is working fine now. However, if I am using below method, it is giving this warning. This method is not advocated since 6.0 Jira version. Please advise.
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, ok. Try to use the getUser(). It is fine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I am running the below code (with getUser())
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.event.type.EventDispatchOption
//import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.UpdateIssueRequest
import org.apache.log4j.Level
import org.apache.log4j.Logger
def LOG = Logger.getLogger("com.onresolve.jira.groovy")
LOG.error("Updating Issue.");
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
MutableIssue updatedIssue = ComponentAccessor.getIssueManager().getIssueObject("TIK-16894")
updatedIssue.setAssigneeId(user.getName())
IssueManager issueManager = ComponentAccessor.getIssueManager();
issueManager.updateIssue(user, updatedIssue, EventDispatchOption.ISSUE_UPDATED, true)
It is giving below error:
No signature of method: com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue() is applicable for argument types: (com.atlassian.jira.user.DelegatingApplicationUser, com.atlassian.jira.issue.IssueImpl, com.atlassian.jira.event.type.EventDispatchOption$EventDispatchOptionImpl, java.lang.Boolean)
Possible solutions: updateIssue(com.atlassian.crowd.embedded.api.User, com.atlassian.jira.issue.MutableIssue, com.atlassian.jira.event.type.EventDispatchOption, boolean), updateIssue(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.MutableIssue, com.atlassian.jira.issue.UpdateIssueRequest)
When I am trying the possible solutions, same error is coming in one way or other.
Please help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you should use getLoggedInUser. Do not pay attention to the warning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It seems that is the only option for the time being. The latest implementation is not returning the value per my requirement. Thank you so much for all your help, Alexey.
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.