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;
}
我有一个像这样的自定义公式:
/**
* 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;
}
这适用于单个公式=IMPORTDATA(A2)
,但是当我将其放在 ArrayFormula=ARRAYFORMULA(IMPORTDATA(A2:A))
中时,结果为 #ERROR 但是当我注释掉 UrlFetchApp.fetch() 时,它可以工作,因此错误似乎来自该方法。有谁知道为什么?