Yes, I’ve been using that page and a couple of others as a guide.
Where I am now: If I remove the code to draw my DataTable, it appears that I get all of the calls I am looking for (I have executed this new code ~15 times and each time I get all of the data back. I print out "data’ each time and it is displaying the results from each call. I am merging each result into “finalJson” and at the end of execution “finalJson” contains an object for each call (an Object of Objects). So my goal is to use “finalJson” to build my DataTable as it contains all of the data.
Results: When I add the code to draw the DataTable inside the success block, I get varying results (this code is not include below). Which I understand because sometimes it is drawing the table before the request has grabbed all of the data. But if I try to access “finalJson” after the requests calls are done, then I’m getting an empty object (result is [] 0 or something like that).
Here is my code block thus far (please forgive any sloppiness as this is not the final code, just code I am using for testing purpose to achieve the desired results).
total: in this environment it is currently (60).
maxResults: set by Atlassian is (25).
screenschemeTable: do not worry about this one for now.
// This is a test function as I work to get the desired results.
function getAllSchemes(total, maxResults, screenschemeTable) {
// Using these to help build the final JSON results.
var mergedJson = [];
var finalJson = [];
console.log("We are here");
// Loop to increment startAt to grab all data in the instance.
for (startIndex = 0; startIndex < total; startIndex+=maxResults) {
//console.log ("Index: " + startIndex);
// This may not be correct as I took it from an Atlassian Community thread.
new Promise((resolve, reject) => {
AP.request('/rest/api/3/screenscheme?startAt=' + startIndex, {
success: function(responseText) {
resolve(responseText);
//console.log("Succcessful!");
//console.log("Response: " + responseText);
// Each pass through I am building the finalJson object.
var data = JSON.parse(responseText);
mergedJson.push(data);
finalJson = $.extend(true, {}, finalJson, mergedJson);
console.log("Data: ", data);
console.log("Final: ", finalJson);
}, // End of success block.
error: function(xhr, statusText, errorThrown) {
reject(arguements);
console.log("Errors");
//console.log("Reject: ", reject(arguments);
} // End of error block.
}) // End of Request block.
}); // End of Promise block.
} // End of for loop block.
console.log("We are done");
} // End of Function.
I know the DataTable code needs to wait until I have the finalJson object. Due to getting undesired results by putting this code into the success: block, I’m pretty sure it should not go there, but if that is true, how to I retain finalJson outside of the request block?
Thanks in advance for straightening me out as this is my first Atlassian App. Everything works like a charm otherwise, but I will need to update a few areas like this one to ensure I am getting all data due to the Atlassian imposed maxResults.