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

147
Visualizações
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 Respostas
Responde à pergunta

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 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