CRM dynamics V9 wait Async web API to contiue code

hello

here is how to do an async call from v9


here is the structur of a call


function azerty ()
{
  Xrm.WebApi.retrieveMultipleRecords("teams", "?$select=name,teamid&$filter="+clause).then(
      function success(result)
        {
    //Your COde here part A       
        },

        function (error)
        {
            Xrm.Navigation.openAlertDialog(error.message);
        }
    );


 //other code here; part b //Yuou want this code to be executed after part A
because the webapi call is assync the part B would be executed before part A

}

then if you want to execute part B after part A here is how to do
In green what is change to make it work

async function azerty ()
{
//Some code

await myPartAcode();

partBcode;


}

function myPartAcode()
{

return new Promise(resolve => { {
resolve(



  Xrm.WebApi.retrieveMultipleRecords("teams", "?$select=name,teamid&$filter="+clause).then(
      function success(result)
        {
            // perform operations on record retrieval
            if (results.entities.length > 0)
            {
              return results;
            }
        },

        function (error)
        {
            Xrm.Navigation.openAlertDialog(error.message);
        }

    );

);

}});

}




we put the web api call between

return new Promise(resolve => { {
resolve(

//WebApiCalland we remove the last ;

);
}});



Commentaires

Posts les plus consultés de ce blog

promise example

Decode/render HTML from a field in crm dynamics