I am passing primary tab ids iteratively into a function to get the sub tub ids of each primary tab.
At the end of this function I have a list of all primary and sub tabs open. How can I iteratively pass these tab ids to the console page view function?
I would think pageInfoProcess() would invoke after the for loop has completed, but it does not which results in a undefined error when looking for the length. I looked in javascript's .then method, but I ran into the same issue as length with the variable being undefined.
<script>
var returnedIds;
var subTabIds;
function getPrimaryTabIdsFromConsole() {
sforce.console.getPrimaryTabIds(function(result) {
returnedIds = result.ids;
for (let k = 0; k < returnedIds.length; k++) {
sforce.console.getSubtabIds(returnedIds[k], function (subTabResults) {
let primaryIdCount = returnedIds.length;
let primaryIdProcessed = 0;
console.log('Subtab Ids Returned: ' + subTabResults.ids);
subTabIds.push(subTabResults.ids);
console.log('subTabIds after subtab push: ' + subTabIds);
primaryIdProcessed += 1;
if (primaryIdProcessed === primaryIdCount) {
allTabIds = returnedIds.push(subTabIds);
console.log('allTabIds: ' + allTabIds);
}
});
}
});
}
</script>