I am currently working on the following code. My goal is to ensure that the values are fully processed before executing the dispatch function. However, the issue I am facing is that the dispatch is happening before all the values are retrieved from the foreach loop.
Any suggestions or solutions would be greatly appreciated. Thank you in advance.
executeSyncPO() {
this.waiting = true;
this.$store.dispatch('account/checkToken', this.optionValues.syncValue).then((res) => {
this.waiting = 'stepTwo';
this.maxCount = res.length;
res.forEach(result => {
this.POValues.po_number = result.DocNumber;
this.POValues.vendor_id = result.VendorRef;
this.POValues.order_date = result.MetaData.CreateTime;
this.POValues.amount = result.TotalAmt;
this.POValues.currency = result.CurrencyRef;
this.POValues.qb_poId = result.Id;
this.POValues.status = result.POStatus;
this.POValues.line = result.Line;
this.$store.dispatch('purchaseOrder/createPO', this.POValues).then(res => {
this.progress += 1;
}).then(() => {
this.$store.dispatch('purchaseOrder/create-lists');
})
})
})
},