Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!