
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Apr 14, 2021 11:27 AM
I have a code that looks like this:
await createPackage(oderSummary);
async function createPackage(oderSummary) {
let pickPosition = true;
let lineItemsArr = [];
const r = Object.keys(oderSummary[0]).map((v) => ({
[v]: oderSummary.map((c) => c[v]),
}));
let tableItem = [...r[2]["Pozycja"]];
while (pickPosition == true) {
let pickItem = await input.buttonsAsync(
"Pick order to pass",
tableItem.map(String)
);
let filteredOrders = oderSummary.filter(
(item) => item.Pozycja !== Number(pickItem)
);
let difference = oderSummary.filter((x) => !filteredOrders.includes(x));
tableItem = tableItem.filter((v) => String(v) !== pickItem);
lineItemsArr.push(difference[0]);
oderSummary = filteredOrders;
if (pozycjaTabeli.length) {
let shouldContinue = await input.buttonsAsync("Dodac Nastepna?", [
{ label: "Yes", value: "Yes" },
{ label: "Cancel", value: "Cancel", variant: "danger" },
]);
if (shouldContinue == "Yes") {
foo(oderSummary, "RecordID");
} else {
pickPosition = false;
}
} else {
pickPosition = false;
}
}
return lineItemsArr;
}
How to can I rewrite the createPackage
function to return the value of lineItemsArr
?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Apr 14, 2021 12:25 PM
Can you provide some more details?
It looks like the function already returns lineItemsArr
.
However, you do not include enough of the code to see where this variable is set or what value it should have.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Apr 14, 2021 02:33 PM
I wrongly assumed the error I was getting has something to do with async function that I haven’t learned yet.
The cause was actually in passing the return of the function to a different function.
The code seems to be working fine. Thank you.
