0

I have been reading alot and trying to assign value of a promise to variable outside function but still wasn't able to find exact example how to solve it in my case. I might be stupid but reading about sync/asynch doesn't really help me. Seems like there strictly problem with getting value from a promise or something...

What should be added to following code to make it able to assign value to variable?

 var mainInvoiceID = "";
function retrieveRowsInvoices() {
    const resultsRowsInvoices = Xrm.WebApi.retrieveMultipleRecords("new_rowsinvoices", filterRowsInvoices);
    return resultsRowsInvoices;

 }
 
 retrieveRowsInvoices().then(function(result) {
    let rows = result.entities[0]._new_idinvoice_value;
    console.log(rows);
    mainInvoiceID = rows;  
  });
Emejcz
  • 47
  • 2
  • 6
  • 1
    It is able to, and does assign to that variable. The big question is: _When_? – tkausl Aug 05 '22 at 21:41
  • 1
    It *is* assigning to the variable. You won't be able to use it immediately, because any code you put right after this will run before the async function returns. – Barmar Aug 05 '22 at 21:42

0 Answers0