Xrm.WebApi calls as synchronous in Dynamics 365/ Dataverse
By default Xrm.WebApi methods are asynchronous so you may get some issues in your script logic. SO how to make this synchronous?
Change the code to use async and await keywords.
The sample code given here.
// form onload method.
async function OnLoad() {
// statement 1
await ReadContacts();
// statement 2
console.log("after contract read. print this.");
// statement 3
await ReadAccounts();
// statement 4
console.log("onload successfully completed.");
}
async function ReadContacts() {
var result = await Xrm.WebApi.retrieveMultipleRecords("contact", "?$select=fullname");
for (var i = 0; i < results.entities.length; i++) {
// your code goes here
}
console.log("ReadContacts completed successfully.");
}
async function ReadAccounts() {
var result = await Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name");
for (var i = 0; i < results.entities.length; i++) {
// your code code here
}
console.log("ReadAccounts completed successfully.");
}
Hope this will help.
Follow my blog for more trending topics on Dynamics 365, Azure, C#, Power Portals and Power Platform. For training, Courses and consulting, call to us at +91 832 886 5778 I am working more for community to share skills in Dynamics 365 and Power Platform. Please support me by subscribing my YouTube Channel. My YouTube Channel link is this : https://www.youtube.com/user/sppmaestro