Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I access the linked issues via javaclass

Jamis A. Mack August 27, 2021

I use an ETL tool to extract jira data and have a new requirement to extract linked issues

Using the following code, I get nulls and empty strings.

 

//flds is output from a GET API call

var _issuelinks = extractIssuelinks(flds.issuelinks.issues)

// I have also tried var _issuelinks = extractIssuelinks(flds.issuelinks-issues)

// following a scriptrunner article referencing issuelinks-issues

// the article is https://scriptrunner.adaptavist.com/5.6.8/jira/recipes/behaviours/working-with-issuelinks.html#_reading_the_value

var checkForValueInIssueLinks = function (_issuelinks, _valueToCheck) {
var retval = "N";
if (_issuelinks != null && _issuelinks.length > 0) {
var issueLen = _issuelinks.length;
for (var i = 0; i < issueLen; i++) {
var buffer = _issuelinks[i] != null && trim(_issuelinks[i]).length > 0 ? trim(_issuelinks[i]) : "";
if (upper(trim(_valueToCheck)).equals(upper(buffer))) {
retval = "Y";
}
}
}
return retval;
}

 

 

1 answer

0 votes
Nic Brough -Adaptavist-
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.
August 27, 2021

I am a bit confused on what you are doing here - how are you trying to read the data from Jira?   You've mentioned up to three different possibilities in the question, and I'm not sure what you are actually doing.

I grab Jira data in a number of ways:

  1. Through the UI, with a browser.  This is the only way the Behaviour script you mention will do anything.
  2. With a get from the UI with a script.  This can get you some data from issues, but it is passive, and none of the javascript (or Behaviours) will execute, and the raw html may not contain a lot of stuff you would see in a browser
  3. With the REST API - that's the recommended way of fetching Jira data with a script or tool
  4. From the database (not possible on Cloud, not recommended on server as the database is absolutely not built for reporting so the queries are usually horrible, requiring a very good understanding of it all, and you have to think about performance and not taking down your server with inefficient queries).  "Last resort" would be a generous description
  5. With apps written for server - this is where a "javaclass" would be used

So, if I had to place a bet on this, my stake would go on option 2. 

Is that what you are doing?

My recommendation would be to move to option 3, the REST API can tell you about links directly in a simple JSON format (far easier to process than the pile of html you get from option 2)

Jamis A. Mack August 31, 2021

Sorry for the confusion.

I AM extracting data from Jira (server) via REST.

My question is how to access the result containing the issuelinks.

This is the code I am using but the results are nulll values. I am using similar code to extract  components and labels successfully. However, issuelinks is not working.  Hope this helps.

 

The expected results are the JIRA keys that populate that field.

var extractIssueLinks = function (_issueLinks) {
  var retval = "";
  if (_issueLinks != null && _issueLinks.length > 0) {
    retval = _issueLinks.join(",");
  }
  return retval.length <= 256 ? retval : substr(retval,0,256);
}

var _issueLinks = extractIssueLinks(flds.issue.issuelinks);

Suggest an answer

Log in or Sign up to answer