EDIT : I put a console.log in the array creator, just before it returns and the array is empty. I have a similar process that creates an array of promises and executes. Any idea as to why this one is returning an empty array from docuSignPromiseArrayCreator()?
async function docuSignPromiseArrayCreator(res, conn, deal) {
console.log("Promise Array Creator Fired");
return new Promise((resolve, reject) => {
let array = [];
console.log(res);
res.forEach(async (res, index) => {
let attachments = await conn.sobject("Attachment").find({
ParentId: res.Id,
});
let iaPromise = DocuSignDecisionHandler(attachments, deal, conn);
array.push(iaPromise);
});
console.log(array);
resolve(array);
return;
});
}
Here is the function that does (pretty much) the same thing in a different way and works.
async function AttachmentPromiseHandler(res, conn) {
return new Promise(async (resolve, reject) => {
let attachmentArray = [];
await res.forEach(async (attachment) => {
let name = JSON.stringify(attachment.Name);
if (name.includes("LD") || name.includes("Line")) {
let ld = downloadPromiseHandler(attachment.Id, attachment.Name, conn);
attachmentArray.push(ld);
}
if (name.includes("Layout")) {
let layout = downloadPromiseHandler(
attachment.Id,
attachment.Name,
conn
);
attachmentArray.push(layout);
}
});
let attachments = await Promise.all(attachmentArray).catch((error) =>
reject(error)
);
resolve(attachments);
});
}