Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda