Hi,
I am keep getting this error "java.lang.NullPointerException: Cannot invoke method getAt() on null object" on the lest line on the below code "def DefectLinkedIssue = ....."
the relevant part of the code:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
def issue = event.issue as Issue
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def DocumentationlinkName = 'Documentation Task'
def DefectLinkedIssue = ComponentAccessor.getIssueLinkManager()?.getLinkCollection(issue, currentUser)?.getOutwardIssues(DocumentationlinkName)[0]
the [0] is what gives you the message when there are no issues in
ComponentAccessor.getIssueLinkManager()?.getLinkCollection(issue, currentUser)?.getOutwardIssues(DocumentationlinkName)
this could work
def DefectLinkedIssueCollection = ComponentAccessor.getIssueLinkManager()?.getLinkCollection(issue, currentUser)?.getOutwardIssues(DocumentationlinkName)
if (DefectLinkedIssueCollection?.size() >0) {
def DefectLinkedIssue = DefectLinkedIssueCollection[0]
}else{
// there are no links
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Looks like getName() and getOutward() return different values.
For e.g. I have link name "clones"
getOutward() returns "clones" ,but getName() returns "Cloners"
See this code it could be helpful
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.link.LinkCollection
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser
IssueManager im = ComponentAccessor.getComponent(IssueManager);
IssueLinkManager ism = ComponentAccessor.getComponent(IssueLinkManager);
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
Issue createdIssue = im.getIssueByKeyIgnoreCase('<IssueKey>');
LinkCollection issueLinksCol = ism.getLinkCollection(createdIssue, currentUser);
Collection<Issue> linkedIssuesCol = issueLinksCol.getAllIssues()
def result="start...<br>";
for (Issue linkedIssue : linkedIssuesCol) {
result+=linkedIssue.getKey()+"<br>";
}
result+="-----------------------------<br>";
Set<IssueLinkType> linkTypesSet = issueLinksCol.getLinkTypes()
String linkName ='clones';
for (IssueLinkType ilt: linkTypesSet){
if(ilt.getOutward()=='clones'){
linkName=ilt.getName();
}
result+=ilt.getOutward()+"<br>";
}
result+="-----------------------------<br>";
List<Issue> myList = issueLinksCol.getOutwardIssues(linkName);
for (Issue iss : myList) {
result+=iss.getKey()+" a <br>";
}
result+="-----------------------------<br>";
result+=linkName;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hello, because this part
ComponentAccessor.getIssueLinkManager()?.getLinkCollection(issue, currentUser)?.getOutwardIssues(DocumentationlinkName)
returns you empty list, hence it can't get element at 0's key
are you sure you are looking for outward issues, or that link name is correct?
I'd recommend experimenting in script console by replasing line
def issue = event.issue as Issue
to
def issue = ComponentAccessor.issueManager.getIssueObject("JIRA-123")
(replace JIRA-123 with your issue key)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.