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

139
Vistas
retrieverecord not assigning the value to the value from the web api?

I'm creating a var where I want to assign it to a var that I get from another entity

function SubmitAction(executionContext) {
var lookupItem = formContext.getAttribute("alfa_member").getValue()[0].id;
var theTotalMembersTravling = formContext.getAttribute("alfa_numberofdependent").getValue();
var remainFlightCredit;

debugger;
Xrm.WebApi.online.retrieveRecord("contact",lookupItem, "?$select=new_remainstravelcredit").then(
     function employessPackage(result) {
        var new_remainstravelcredit = result["new_remainstravelcredit"];
        if(new_remainstravelcredit !== null){
        if(new_remainstravelcredit > 0)
        {
            remainFlightCredit = new_remainstravelcredit;
            console.log(remainFlightCredit+" This not inside any if condition");

                    var newRemain = (parseInt(remainFlightCredit)) - (parseInt(theTotalMembersTravling));
                    console.log(newRemain+ " This in the remain if condition");
                    var entity = {};
                    entity.new_remainstravelcredit = newRemain.toString();
                    Xrm.WebApi.online.updateRecord("contact",lookupItem, entity).then(
                    function success(result) {
                        var updatedEntityId = result.id;
                    },
                    function(error) {
                        Xrm.Utility.alertDialog(error.message);
                    }
                );
        } if(new_remainstravelcredit <= 0)
        {
            Xrm.Utility.alertDialog("You have exceeds the travel credit");
            console.log(remainFlightCredit);

        } 
    }
    },
    function(error) {
        Xrm.Utility.alertDialog(error.message);
    }
);



  console.log(remainFlightCredit);
}

So as result in this line

 remainFlightCredit = new_remainstravelcredit;
 console.log(remainFlightCredit+" This not inside any if condition");

Which inside the webapi call I'm able to get the value but outside in the main function at the end when I write

      console.log(remainFlightCredit);

I'm unable to get the value remainFlightCredit, do you have any suggestions to solve this issue?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is expected behavior, as this is a promise call (asynchronous) the code outside the main api call will execute before the success callback function employessPackage.

So remainFlightCredit value get assigned after the last console.log line in your code.

You can place a breakpoint to debug and see it in action.

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