Hi All,
I need help in scriptrunner :
Trying to fetch all linked issues linktype outward & inward description of current issue's parent ticket.
And join together of same linktype in json format .I have mentioned below example.
For example :
{ "Includes" : [ "ABC-123", "ABC-334", ], "Relates" : [ "XYZ-456", "XYZ-118", ], }
Appreciate your help !
Here is the code snippet which i have written but output is not in expected format :
Output :
Hi @Sam
Perhaps this is not at all optimal and under certain conditions it may not work but try
import com.atlassian.jira.issue.fields.rest.json.JsonData
import groovy.json.JsonBuilder
import org.jdom.Content
import groovy.json.JsonOutput
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.Attachment
import org.apache.commons.io.FilenameUtils
import com.atlassian.jira.util.io.InputStreamConsumer
import org.springframework.util.StreamUtils
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.URIBuilder
import groovyx.net.http.ContentType
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseDecorator
import javax.servlet.http.HttpServletRequest
import javax.ws.rs.core.Response
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean
import java.io.ByteArrayInputStream
import java.math.MathContext
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkImpl
import com.atlassian.jira.issue.link.IssueLinkTypeImpl
def attachmentManager = ComponentAccessor.getAttachmentManager()
def issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-123")
def IssueLinkManager = ComponentAccessor.getIssueLinkManager()
def links = "[";
List allOutIssueLink = IssueLinkManager.getInwardLinks(issue.getId())
links += "\"${allOutIssueLink[0].issueLinkType.getOutward()}\": "
links += "["
int i = 0
allOutIssueLink.each{link ->
if (i == 0){
links +=link.getSourceObject().key
i++
} else{
links += ", " + link.getSourceObject().key
i++
}
}
links += "], "
log.warn(links)
allOutIssueLink = IssueLinkManager.getOutwardLinks(issue.getId())
links += "\"${allOutIssueLink[0].issueLinkType.getInward()}\": "
links += "["
i = 0
allOutIssueLink.each{link ->
if (i == 0){
links +=link.getSourceObject().key
i++
} else{
links += ", " + link.getSourceObject().key
i++
}
}
links += "]"
links += "]"
log.warn("Links : ${links}")
def json = JsonOutput.toJson(links)
def json_beauty = JsonOutput.prettyPrint(json)
log.warn("json_beauty : ${json_beauty}")
Hi, you have this error because issue which you want get links doesn't have inward links. Look at picture. Do you have both types of links in your issue?
If no you can add some check like this
def attachmentManager = ComponentAccessor.getAttachmentManager()
def issue = ComponentAccessor.getIssueManager().getIssueObject("TESTTEST-176")
def IssueLinkManager = ComponentAccessor.getIssueLinkManager()
def links = "[";
List allOutIssueLink = IssueLinkManager.getInwardLinks(issue.getId())
if (allOutIssueLink ){
links += "\"${allOutIssueLink[0].issueLinkType.getOutward()}\": "
links += "["
int i = 0
allOutIssueLink.each{link ->
if (i == 0){
links +=link.getSourceObject().key
i++
} else{
links += ", " + link.getSourceObject().key
i++
}
}
links += "], "
}
log.warn(links)
allOutIssueLink = IssueLinkManager.getOutwardLinks(issue.getId())
if (allOutIssueLink ){
links += "\"${allOutIssueLink[0].issueLinkType.getInward()}\": "
links += "["
i = 0
allOutIssueLink.each{link ->
if (i == 0){
links +=link.getSourceObject().key
i++
} else{
links += ", " + link.getSourceObject().key
i++
}
}
links += "]"
links += "]"
}
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.