I am creating an issue using listener from one of the workflow transitions.
Now can one help with adding watchers to this newly created issue because we will not be having the issue key to be passed.
I want to add reporter from the parent issue to be copied to newly copied issue under watchers.
Hi,
May you try this code ?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def watcherManager = ComponentAccessor.getWatcherManager()
def issueManager = ComponentAccessor.getIssueManager()
def watchers = issueManager.getWatchersFor(issue.getParentObject())
for (ApplicationUser watcher:watchers){
watcherManager.startWatching(watcher, issue)
}
Also make sure you are working on a sub-task to not get an error.
Actually I am trying to create a new ticket in different project from one of the transitions using Listener
So in your code issue refers to current issue rite?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Absolutely. "issue" is the subtask that is being created.
Do you need more help ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How to get reporter value for the parent object. I am trying to copy reporter value of parent object to watchers in child.
Also this is not a sub task request. It is a new issue being created but not of the type sub task
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah sorry, I thought you wanted to add all the watchers from the parent issue to the child issue.
Then this should work :
import com.atlassian.jira.component.ComponentAccessor
def watcherManager = ComponentAccessor.getWatcherManager()
watcherManager.startWatching(issue.getParentObject().getReporter(), issue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried with above code and I am getting below error
java.lang.NullPointerException: Cannot invoke method getReporter() on null object
This is because parent object is returning null. This is not a sub task being created . I am just clicking on one of the button on transition screen and new ticket in different project is being created
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, have you solved your problem ?
If I understand correctly you need to retrieve the linked issue instead of the parent issue ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes i am looking for the linked issue only not the parent one..but here i m not trying to create any link..just i would be creating the ticket using listener from one of the transition screen..
So i am not finding a way to add watchers here because startwatching method is expecting issue as one of the parameter n I dont know how to pass that parameter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you could use the linkedIssue object depending on the link type (inwards or outwards) :
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.component.ComponentAccessor;
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
def linkedIssue = issueLink.getDestinationObject()
}
List<IssueLink> allInIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allInIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
def linkedIssue = issueLink.getDestinationObject()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But i am not trying to establish any link ..on clicking a transition screen ,issue in a different project gets created..i m not establishing any link
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well you said you are linking the two issues. In that case you can use
watcherManager.startWatching(linkedIssue.getReporter(), issue)
If there is no link between the two issues, you cannot retrieve the "source" issue, unless you use a trick like storing the key in a custom field or something similar. I would strongly suggest to just create a link between the two issues though.
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.