Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
array Length not reporting

This should be simple, but it doesnt make sense to me. It is a simple section of a promise chain

let flightName = [];
let guidArr = [];

Promise.all(guidArr)
       .then(values => {
         for(var a = 0; a < values.length; a++) {
           Xrm.WebApi
              .online
              .retrieveRecord("crd80_flightplanevent", values[a], "?$select=_crd80_learnerflight_value")
              .then(
                function success(result) {
                  flightName.push(result["_crd80_learnerflight_value@OData.Community.Display.V1.FormattedValue"])
                },
                function(error) {
                  DisplayError(error)
                }); 
         }
         return flightName
       }).then(flightName => {
         console.log(flightName) 
         console.log(flightName.length)         
         return flightName
       })

Console log

The console displays the flightName array correctly, but flightName.length is always consoled as 0, even though console.log(flightName) puts length:2 as the output

Why??? I need to work with each item in the array but it is not recognised correctly

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The recommendation by @derpircher worked:

You are not awaiting the promises in your for(var a = 0; a < values.length; a++) loop. Thus, when you do return flightName the array is still empty, and thus console.log(flightName.length) prints 0. The output from console.log(flightName) might pretend, that flightName contains values, but actually it does not because that console.log is referencing the object, which is later filled when the promises resolve. Do console.log(JSON.stringify(flightName)) and you will see it prints just [] because at that moment, the array is still empty

To resolve that issue, make the first then handler async and use await Xrm.WebApi... or properly wrap that whole thing in a Promise.all

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda