0
function getContentForAPI(path) 
{
  var result = {};

  result.url = "https://" + HOST + "/rest/api/2/" + path;
  result.response = UrlFetchApp.fetch(result.url, API_HEADERS);
  result.text = result.response.getContentText();

  try { result.data = JSON.parse(result.text); } catch(error) {}

  return result;
}

I have a custom formula like such:

/**
 * Import data.
 *
 * @param {string} the ID that belongs to the issue.
 * @return The summary.
 * @customfunction
 */
function IMPORTDATA(issueID) 
{
  var details = [];

  if (issueID instanceof Array) {
    var issueIDs = issueID;
    for (i in issueIDs){
      for (j in issueIDs[i]){
        issueID = issueIDs[i][j];

        var content = getContentForAPI("issue/"+issueID);
        if (content == undefined || content.data == undefined) {
          details.push(["G","H"]);
        } else {
          details.push(["E", "F"]);
        }
      }
    }
  } else {
    var content = getContentForAPI("issue/"+issueID);
    if (content.data != undefined) {
      details.push([content.data.fields.project.name, content.data.fields.summary]);
    }
  }

  return details;
}

This works for a single formula =IMPORTDATA(A2) however when I put it within an ArrayFormula =ARRAYFORMULA(IMPORTDATA(A2:A)) the result is #ERROR however when I comment out UrlFetchApp.fetch() it works so the error seems to be coming from that method. Does anyone know why?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Mark
  • 16,906
  • 20
  • 84
  • 117
  • You have to write the function to work with arrays. See this [Help Forum Topic](https://productforums.google.com/forum/#!topic/docs/RvUuxRw7U50) where a sheet is posted with sample code. You have to copy the file to get to the code. – Karl_S Mar 29 '17 at 13:16
  • Karl_S, as you can see it works with the array 'instanceof Array'-part however when you a function like Utitlitiy.sleep(2) or getProperty or UrlFetchApp.fetch() it gives an error. – Mark Mar 29 '17 at 13:41

0 Answers0