when i try to create a new record from JS to CRM with the function XrmServiceToolkit.Soap.Create its take a lot of time to finish.. so the JS continuing to execute the other function, in the function RecalculateSurface i retreive the value of the record created by the first function so i can't get the value of record because its not saved yet.
function save()
{
//some code
delivery.attributes["eoz_unit"] = Unit;
delivery.attributes["description"] = quoteDetail.Description;
delivery.attributes["quoteid"] = { id: quoteId, logicalName: "quote", type: "EntityReference" };
XrmServiceToolkit.Soap.Create(delivery); //function 1
RecalculateSurface();
}
function RecalculateSurface()
{
// code to retreive the record created in function 1
}
any idea to make the function RecalculateSurface() wait the save of the record? the function XrmServiceToolkit.Soap.Create return the id of the record created.
So, the create function has an optional callback function parameter...
XrmServiceToolkit.Soap.Create(businessEntity, [callback(result)]);
You should use that option instead of just passing in entity
This should cause the XrmServiceToolkit.Soap.Create call to operate asynchronously and only call RecalculateSurface() when it completes.
If you want to expand the solution to use promises then you could do the following: