I'm trying to fetch the Jira tickets from a project using a Google Sheets script, but it's only bringing in tickets with a gap of about a month and a half. No matter how I sort or filter by date, it stops after around 45-50 days between the first and last ticket it retrieves, regardless of the number of tickets fetched. What could be causing this?
The script follows this structure (forget about the names) Thanks a lot!!
Hi @Pablo Canto
Please correct me if I am missing anything but in your code totalResults variable being set to 1000, which could be limiting the number of issues retrieved. Your script iterates until startAt < totalResults
(which is 1000), as of my understanding.
If your project has more than 1000 issues, the script will stop fetching after reaching this limit, even though older issues exist. The gap of ~45-50 days could be because the first 1000 most recent issues fit within that range.
Remove or increase totalResults and test again if possible.
first of all, thanks for your reply! I don't think that's the problem since I'm just getting 20 tickets if I order them asc or around 550 if I order them desc in date of creation. I've tried to change that 1000 number and even with a higher number, it doesn't bring me all the Jiras I expected
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see!
Can you please replace that function with the one below and try? See the logs on what's going on.
function fetchJiraIssues() {
let startAt = 0;
let allIssues = [];
let totalResults = null;
while (true) {
const url = `${jiraDomain}/rest/api/2/search?jql=project=CRM ORDER BY created DESC&maxResults=${maxResultsPerPage}&startAt=${startAt}`;
const options = {
method: 'get',
headers: {
Authorization: 'Basic ' + Utilities.base64Encode(jiraUser + ':' + apiToken),
'Accept': 'application/json'
}
};
try {
const response = UrlFetchApp.fetch(url, options);
const data = JSON.parse(response.getContentText());
if (totalResults === null) {
totalResults = data.total;
Logger.log(`Total issues available: ${totalResults}`);
}
if (!data.issues || data.issues.length === 0) break;
allIssues = allIssues.concat(data.issues);
startAt += maxResultsPerPage;
if (startAt >= totalResults) break;
} catch (e) {
Logger.log("Error fetching Jira issues: " + e.message);
break;
}
}
return allIssues;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.