I need to loop through a json and make multiple getitem calls to dynamo db. My issue is that node js flies through the code not waiting for the function return so I can't create an xml that has a header, multiple calculated lines, and then a footer.
In the sample below, the !make footer would be written long before the function taxrate finishes. How can I force the script to wait for the taxrate function to finish?
!make xml header
for(i=0; i<linelength; i++)
{
business_unit = '100'
invoice_line = 1
total = 100
taxrate(business_unit, invoice_line, total);
!write line xml
}
!make xml footer
function taxrate(business_unit, i, gross_total) {
const params = {
Key: {
"tax_rate": {
S: business_unit
}
},
TableName:"tax_table"
};
dynamodb.getItem(params,function(err, data){
if(err) {
console.log("call error");
console.log(err);
} else {
console.log(data.Item.tax.N);
return(data.Item.tax.N);
}
});