Skip to main content

Notifications

Community site session details

Community site session details

Session Id :

Back to Basics # 61: Usage of async and await with Webresource in Dynamics CRM[Telugu]

codevenkat Profile Picture Posted by codevenkat 126

Await / Async is built on promises and is a clean way to represent asynchronous processes in a synchronous way. In Dynamics 365 async and await are used especially while working with web api calls so that until promise gets completed other part of the code will not get executed. As an example, on selected contact record this behaviour was shown .

 

English version of Blog :
https://venkatasubbaraopolisetty.com/2022/06/29/back-to-basics-61-usage-of-async-and-await-with-webresource-in-dynamics-crm/

 

Thanks for watching. You can find me in the following places:
🎯 Website: https://venkatasubbaraopolisetty.com/

🎯 Twitter: https://twitter.com/Venkata48681009

🎯 LinkedIn: https://www.linkedin.com/in/venkata-subbarao-polisetty-mvp-mct-54116618/

Categories:

Dataverse

Comments

  • Ajithnair621 Profile Picture Ajithnair621 83
    Posted at
    Back to Basics # 61: Usage of async and await with Webresource in Dynamics CRM[Telugu]

    They delay too can be set for a maximum of 10 seconds as I understood from some community posts.

  • codevenkat Profile Picture codevenkat 126
    Posted at
    Back to Basics # 61: Usage of async and await with Webresource in Dynamics CRM[Telugu]

    Try to use delay functionality with  setTimeout() function 

  • Ajithnair621 Profile Picture Ajithnair621 83
    Posted at
    Back to Basics # 61: Usage of async and await with Webresource in Dynamics CRM[Telugu]

    I have written a simple code to test ASYNC and AWAIT on my PowerApps environment. It is as seen in below code. Display function has been placed onSave of Form.

    Unfortunately when i execute below code system does not stop saving the record.
    I have referred following links too. 
    https://debajmecrm.com/are-you-using-async-functions-in-your-webresources-yet-in-dynamics-365-they-can-make-your-code-look-much-readable-by-removing-the-clutter-of-then-constructs-to-handle-each-promise-evaluation-chec/
    https://debajmecrm.com/how-to-make-xrm-webapi-calls-synchronous-in-dynamics-365-cds/
    https://debajmecrm.com/async-onsave-handlers-in-dataverse-dynamics-365-forms-to-cancel-save-operation-stop-save-till-certain-async-events-are-executed-check-this-out/

    var synchandling = window.synchandling || {};
    (
        function () {
            "use strict";
            this.displaySynchronousConfirmationDialogBox = async function (executionContext, displayConfirmationMessage) {
                var formContext = executionContext.getFormContext();
                var formSaveEvent = executionContext.getEventArgs();
                var confirmStrings = {
                    text: displayConfirmationMessage,
                    title: "CONFIRMATION"
                };
                var confirmOptions = {
                    height: 200,
                    width: 250
                };

                let userResponse = await Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(
                    function (success) {
                        if (!success.confirmed) {
                            if (formSaveEvent)
                                formSaveEvent.preventDefault();
                            return true;
                        }
                        else
                            return false;
                    }
                );
                return userResponse;
            }
        }
    ).call(synchandling);