SlideShare a Scribd company logo
Tips & Tricks for New Async Web Client
Capabilities on Model-Driven-Apps
MALAYSIA DYNAMICS 365 & POWER PLATFORM USER GROUP -
OCTOBER 2021 MEETUP
Mehdi El Amri
Business App Consultant @Umanis
Specialize in Microsoft Dynamics CE & Power Platform
Contributor @Community.Dynamics.com
Blogger
Futur Speaker 
https://community.dynamics.com/members/meelamri
https://xrmtricks.com/
@meelamri1
linkedin.com/in/meelamri/
Agenda
Intro:
 MDA Client Scripting
 Sync Events vs Async Events
 DEMO (1)
New Async Capabilities
Async OnSave Event
 App Configuration
 DEMO (2)
Async Custom Enable Rule
 How is work ?
 DEMO (DEMO 3)
Async OnLoad Event
 App Configuration
 DEMO (4)
Recap & resources
Intro - MDA Client Scripting
 Client Scripting using a RICH JavaScript client APIS.
 Execute JS CODE reacting to events:
 Form Loads
 Form Save
 Column Change
 Process Change …
 Never interact with the DOM directly. Always use
the Microsoft Client API
Supported Events: https://docs.microsoft.com/en-
us/powerapps/developer/model-driven-
apps/clientapi/reference/events
Intro - Sync Event
 When a task is executed synchronously, this means that we wait for one task to be completed
before moving on to another  One task depends on the completion of another.
Task 1 Task 2 Task 3
Start Finish
Sync Event: Tasks are executed synchronously
Intro - Async Events
 When a task is executed asynchronously, you can directly switch to another task before the
previous has been completed  One task does not depend on the other.
Task 1
(Start)
Task 2
(Start)
Start Finish
Task 1
(Finish)
Task 2
(Finish)
Async Event: Tasks can be executed asynchronously
Intro – Async Task in Sync Event (1)
 Sync events are supposed to execute synchronous tasks, but nothing prevents the
implementation of asynchronous tasks.
Task 1
Async Task 2
Start
Task 3
Start Finish
Async Task 2
Finish
Sync Event
Intro – Async Task in Sync Event (2)
 Scenario:
 When a column is changed, a function will be triggered that will execute an asynchronous code that
displays a dialog box. The resolution of the asynchronous code will be done in 5 seconds.
 DEMO (1)
New Async Capabilities (1)
Historically, the Client API implemented only synchronous events. Developers used
workarounds to synchronize their asynchronous code.
One example is to display a button based on the result of an asynchronous operation:
 To implement this, we use a Custom Enable Rule.
 This kind of code is executed synchronously.
 The Custom Enable Rule returns a value before the execution of the asynchronous operation is finished.
 The idea was to have a global variable to store the result of the asynchronous operation and to execute
the enable rule a second time. At the second execution, we retrieve the value from the global variable
instead of executing the asychronous operation for the second.
 Example: https://butenko.pro/2018/11/13/showing-ribbon-button-based-on-the-result-of-async-
operation/
New Async Capabilities (2)
Starting this year, the API client are beginning to support asynchronous events. These are the
following events:
 OnSave Event
 Custom Enable Rules
 OnLoad Event (not yet documented)
These capabilities will help developers to synchronize asynchronous code in an efficient way and
to use the power of the JavaScript to implement quite complex scenarios with less effort !
Please note that the OnLoad event is not yet officially supported. I do not recommend using the
asychronous capability for this event in Production at this time.
Async OnSave Event (1)
This event is triggered when a form is saved. This saving can be done manually by a user or
automatically by a JavaScript code.
The client API gives us the ability to implement an asynchronous logic when triggering this
event.
This new capability is not applied by default. Indeed, this behavior is strongly linked to the
application we use. In effect, the MDA must be configured to support this behavior.
This kind of behavior will allow us to easily implement validations using asynchronous
operations. For example, validating an email address or a phone number through a third party
API.
Docs suggests a method that requires manipulation of the app's XML definition to enable
asynchronous capability. I propose an easier and faster way to enable asynchronous capability
for your applications.
Async OnSave Event (2)
To enable asynchronous capability for the OnSave event in your app:
 Open the console and type the following script:
Async OnSave Event (3)
After the script execution, we can check that the Asynchronous behavior is applied for our app
by using the following query:
 /api/data/v9.2/appsettings?$filter=(contains(uniquename, '%AsyncOnSave%'))
Async OnSave Event (4)
Scenario:
 Validate the phone number of the contact before saving.
 Use Power Automate for validation:
 Validation in less than 10 seconds.
 What happens if the flow does not respond after 10 seconds.
DEMO (2):
 Display a dialog message confirming the save after Cloud Flow Validation.
 Cancel the save if the flow does not validate the phone number and display a message
 Display an error if the execution time exceeds 10 seconds.
Async Custom Enable Rule
Custom Enables Rules are rules implemented in JavaScript that decide on the display of the
ribbon buttons.
Custom Enables rules support returning a Promise rather than boolean for asynchronous rule.
Scenario:
 Display/Hide a button based on the result of async operation.
DEMO (3):
 We will use the same Cloud Flow as DEMO (2)
 Button is shown when the promise is resolved
 Button is hidden when the promise is rejected
 Code only … I didn’t add the button to my form  !!
Async OnLoad Event (1)
This event is triggered when a form is loading.
The client API gives us the ability to implement an asynchronous logic when triggering this
event.
This new capability is not applied by default. This behavior is strongly linked to the application
we use. In effect, the MDA must be configured to support this behavior.
This kind of behavior will allow us to easily implement some asynchronous logic before
displaying a form. For example, we can change the form based on an attribute value.
At the moment, this behavior is not yet documented, so it is not yet supported. We can enable
this behavior in the same way as the Save event.
Async OnLoad Event (2)
To enable asynchronous capability for the OnLoad event in your app:
 Open the console and type the following script:
Async OnLoad Event (3)
After the script execution, we can check that the Asynchronous behavior is applied for our app
by using the following query:
 /api/data/v9.2/appsettings?$filter=(contains(uniquename, '%AsyncOnLoad%'))
Async OnLoad Event (4)
Scenario:
 Display the right form according to the result of an asynchronous operation
 We will mock the asynchronous action with the setTimeout() function
DEMO (4):
 What happen if the Load Event was Synchronous ?
 https://meelamri.files.wordpress.com/2021/05/synconload-event.gif?w=600
 What happen if the asynchronous operation is not resolved after 10 seconds ?
Recap & resources
Recap:
 Difference between Sync and Async Event
 Client API support 2 Async Events: OnLoad and OnSave
 OnChange Event is Sychronous !!
 Custom Enable Rules support Asynchronous operations
Resources:
 Docs:
 https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference
 https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/events/form-onsave
 https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/customize-dev/define-ribbon-
enable-rules?view=op-9-1#custom-rule
 Demos source code:
 https://gist.github.com/melamriD365/a42ff66001285cbdd07d685a6daabbee
Tips and Tricks for new async web client capabilities on model driven apps

More Related Content

PDF
Event storming
PPTX
Accel series 2023 Spring
PDF
Provisioning Datadog with Terraform
PPTX
BPMN to UML
PPTX
ServiceNow - Introduction.pptx
PDF
How we reduced logs costs by moving from Elasticsearch to Grafana Loki
PDF
Soft skills para pessoas de tecnologia
PDF
Infrastructure as Code
Event storming
Accel series 2023 Spring
Provisioning Datadog with Terraform
BPMN to UML
ServiceNow - Introduction.pptx
How we reduced logs costs by moving from Elasticsearch to Grafana Loki
Soft skills para pessoas de tecnologia
Infrastructure as Code

What's hot (20)

PPTX
Overview on Agile, Scrum, Kanban, Extreme programming (XP) and Scaled Agile F...
PPSX
Termo de Abertura do Projeto
PDF
Testing modern webapps. At scale.
PDF
Team Trust Canvas eng
PPTX
Stac2021 [初学者向け]ローコード開発におけるテストの考え方
PDF
Autonomous Machines with Project Bonsai
PDF
Introducción a arquitecturas y herramientas de Big Data.pdf
PDF
SIEMENS Solution Partners in Russia and CIS
PDF
「ドメイン駆動設計」の複雑さに立ち向かう
PPTX
Accel series 2022_winter
PDF
Agile Simplified
PDF
Administração de Operações - Introdução
PDF
アジャイル開発の中の設計
PDF
Microservices at Spotify
PDF
From Principles to Strategies for Systems Engineering
PDF
The Challenges of Agile Adoption
PDF
Scrum - Fundamentos, teorias e práticas!
PDF
Lean Change Management - チーム・組織に変化を起こす!オリジナルのチェンジ・フレームワークを構築する方法
PDF
Spring Bootハンズオン ~Spring Bootで作る マイクロサービスアーキテクチャ! #jjug_ccc #ccc_r53
PDF
Usando o Agile Coaching Competency Framework para evoluir na carreira de Agil...
Overview on Agile, Scrum, Kanban, Extreme programming (XP) and Scaled Agile F...
Termo de Abertura do Projeto
Testing modern webapps. At scale.
Team Trust Canvas eng
Stac2021 [初学者向け]ローコード開発におけるテストの考え方
Autonomous Machines with Project Bonsai
Introducción a arquitecturas y herramientas de Big Data.pdf
SIEMENS Solution Partners in Russia and CIS
「ドメイン駆動設計」の複雑さに立ち向かう
Accel series 2022_winter
Agile Simplified
Administração de Operações - Introdução
アジャイル開発の中の設計
Microservices at Spotify
From Principles to Strategies for Systems Engineering
The Challenges of Agile Adoption
Scrum - Fundamentos, teorias e práticas!
Lean Change Management - チーム・組織に変化を起こす!オリジナルのチェンジ・フレームワークを構築する方法
Spring Bootハンズオン ~Spring Bootで作る マイクロサービスアーキテクチャ! #jjug_ccc #ccc_r53
Usando o Agile Coaching Competency Framework para evoluir na carreira de Agil...
Ad

Similar to Tips and Tricks for new async web client capabilities on model driven apps (20)

PPT
Ajaxppt
PPTX
Android 101 Session @thejunction32
KEY
Functional UI testing of Adobe Flex RIA
PDF
Active object of Symbian in the lights of client server architecture
PPTX
How to implement Micro-frontends using Qiankun
PDF
Asp.net+interview+questions+and+answers
PPT
Is It The Cloud, The App, Or Just Me
PPT
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
DOCX
Loadrunner interview questions and answers
PPTX
Debugging lightning components-SEDreamin17
PPTX
Architecting Microservices in .Net
PDF
Real-time Text Audio to Video PPT Converter Tablet App
PPTX
Connecting Xamarin Apps with IBM Worklight in Bluemix
 
PDF
15minutesintroductiontoappdynamics1.pdf
PDF
AWS Step Functions
PDF
Free advertising platform for businesses with IOS & Android Apps development
PDF
Free advertising platform for businesses with IOS & Android Apps development
PPTX
Save Azure Cost
PDF
How to integrate flurry in android
PDF
Appium understanding document
Ajaxppt
Android 101 Session @thejunction32
Functional UI testing of Adobe Flex RIA
Active object of Symbian in the lights of client server architecture
How to implement Micro-frontends using Qiankun
Asp.net+interview+questions+and+answers
Is It The Cloud, The App, Or Just Me
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
Loadrunner interview questions and answers
Debugging lightning components-SEDreamin17
Architecting Microservices in .Net
Real-time Text Audio to Video PPT Converter Tablet App
Connecting Xamarin Apps with IBM Worklight in Bluemix
 
15minutesintroductiontoappdynamics1.pdf
AWS Step Functions
Free advertising platform for businesses with IOS & Android Apps development
Free advertising platform for businesses with IOS & Android Apps development
Save Azure Cost
How to integrate flurry in android
Appium understanding document
Ad

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
20250228 LYD VKU AI Blended-Learning.pptx
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
MYSQL Presentation for SQL database connectivity
Approach and Philosophy of On baking technology
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Programs and apps: productivity, graphics, security and other tools
The Rise and Fall of 3GPP – Time for a Sabbatical?
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
sap open course for s4hana steps from ECC to s4
Reach Out and Touch Someone: Haptics and Empathic Computing
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Building Integrated photovoltaic BIPV_UPV.pdf
MIND Revenue Release Quarter 2 2025 Press Release
A comparative analysis of optical character recognition models for extracting...
Advanced methodologies resolving dimensionality complications for autism neur...

Tips and Tricks for new async web client capabilities on model driven apps

  • 1. Tips & Tricks for New Async Web Client Capabilities on Model-Driven-Apps MALAYSIA DYNAMICS 365 & POWER PLATFORM USER GROUP - OCTOBER 2021 MEETUP
  • 2. Mehdi El Amri Business App Consultant @Umanis Specialize in Microsoft Dynamics CE & Power Platform Contributor @Community.Dynamics.com Blogger Futur Speaker  https://community.dynamics.com/members/meelamri https://xrmtricks.com/ @meelamri1 linkedin.com/in/meelamri/
  • 3. Agenda Intro:  MDA Client Scripting  Sync Events vs Async Events  DEMO (1) New Async Capabilities Async OnSave Event  App Configuration  DEMO (2) Async Custom Enable Rule  How is work ?  DEMO (DEMO 3) Async OnLoad Event  App Configuration  DEMO (4) Recap & resources
  • 4. Intro - MDA Client Scripting  Client Scripting using a RICH JavaScript client APIS.  Execute JS CODE reacting to events:  Form Loads  Form Save  Column Change  Process Change …  Never interact with the DOM directly. Always use the Microsoft Client API Supported Events: https://docs.microsoft.com/en- us/powerapps/developer/model-driven- apps/clientapi/reference/events
  • 5. Intro - Sync Event  When a task is executed synchronously, this means that we wait for one task to be completed before moving on to another  One task depends on the completion of another. Task 1 Task 2 Task 3 Start Finish Sync Event: Tasks are executed synchronously
  • 6. Intro - Async Events  When a task is executed asynchronously, you can directly switch to another task before the previous has been completed  One task does not depend on the other. Task 1 (Start) Task 2 (Start) Start Finish Task 1 (Finish) Task 2 (Finish) Async Event: Tasks can be executed asynchronously
  • 7. Intro – Async Task in Sync Event (1)  Sync events are supposed to execute synchronous tasks, but nothing prevents the implementation of asynchronous tasks. Task 1 Async Task 2 Start Task 3 Start Finish Async Task 2 Finish Sync Event
  • 8. Intro – Async Task in Sync Event (2)  Scenario:  When a column is changed, a function will be triggered that will execute an asynchronous code that displays a dialog box. The resolution of the asynchronous code will be done in 5 seconds.  DEMO (1)
  • 9. New Async Capabilities (1) Historically, the Client API implemented only synchronous events. Developers used workarounds to synchronize their asynchronous code. One example is to display a button based on the result of an asynchronous operation:  To implement this, we use a Custom Enable Rule.  This kind of code is executed synchronously.  The Custom Enable Rule returns a value before the execution of the asynchronous operation is finished.  The idea was to have a global variable to store the result of the asynchronous operation and to execute the enable rule a second time. At the second execution, we retrieve the value from the global variable instead of executing the asychronous operation for the second.  Example: https://butenko.pro/2018/11/13/showing-ribbon-button-based-on-the-result-of-async- operation/
  • 10. New Async Capabilities (2) Starting this year, the API client are beginning to support asynchronous events. These are the following events:  OnSave Event  Custom Enable Rules  OnLoad Event (not yet documented) These capabilities will help developers to synchronize asynchronous code in an efficient way and to use the power of the JavaScript to implement quite complex scenarios with less effort ! Please note that the OnLoad event is not yet officially supported. I do not recommend using the asychronous capability for this event in Production at this time.
  • 11. Async OnSave Event (1) This event is triggered when a form is saved. This saving can be done manually by a user or automatically by a JavaScript code. The client API gives us the ability to implement an asynchronous logic when triggering this event. This new capability is not applied by default. Indeed, this behavior is strongly linked to the application we use. In effect, the MDA must be configured to support this behavior. This kind of behavior will allow us to easily implement validations using asynchronous operations. For example, validating an email address or a phone number through a third party API. Docs suggests a method that requires manipulation of the app's XML definition to enable asynchronous capability. I propose an easier and faster way to enable asynchronous capability for your applications.
  • 12. Async OnSave Event (2) To enable asynchronous capability for the OnSave event in your app:  Open the console and type the following script:
  • 13. Async OnSave Event (3) After the script execution, we can check that the Asynchronous behavior is applied for our app by using the following query:  /api/data/v9.2/appsettings?$filter=(contains(uniquename, '%AsyncOnSave%'))
  • 14. Async OnSave Event (4) Scenario:  Validate the phone number of the contact before saving.  Use Power Automate for validation:  Validation in less than 10 seconds.  What happens if the flow does not respond after 10 seconds. DEMO (2):  Display a dialog message confirming the save after Cloud Flow Validation.  Cancel the save if the flow does not validate the phone number and display a message  Display an error if the execution time exceeds 10 seconds.
  • 15. Async Custom Enable Rule Custom Enables Rules are rules implemented in JavaScript that decide on the display of the ribbon buttons. Custom Enables rules support returning a Promise rather than boolean for asynchronous rule. Scenario:  Display/Hide a button based on the result of async operation. DEMO (3):  We will use the same Cloud Flow as DEMO (2)  Button is shown when the promise is resolved  Button is hidden when the promise is rejected  Code only … I didn’t add the button to my form  !!
  • 16. Async OnLoad Event (1) This event is triggered when a form is loading. The client API gives us the ability to implement an asynchronous logic when triggering this event. This new capability is not applied by default. This behavior is strongly linked to the application we use. In effect, the MDA must be configured to support this behavior. This kind of behavior will allow us to easily implement some asynchronous logic before displaying a form. For example, we can change the form based on an attribute value. At the moment, this behavior is not yet documented, so it is not yet supported. We can enable this behavior in the same way as the Save event.
  • 17. Async OnLoad Event (2) To enable asynchronous capability for the OnLoad event in your app:  Open the console and type the following script:
  • 18. Async OnLoad Event (3) After the script execution, we can check that the Asynchronous behavior is applied for our app by using the following query:  /api/data/v9.2/appsettings?$filter=(contains(uniquename, '%AsyncOnLoad%'))
  • 19. Async OnLoad Event (4) Scenario:  Display the right form according to the result of an asynchronous operation  We will mock the asynchronous action with the setTimeout() function DEMO (4):  What happen if the Load Event was Synchronous ?  https://meelamri.files.wordpress.com/2021/05/synconload-event.gif?w=600  What happen if the asynchronous operation is not resolved after 10 seconds ?
  • 20. Recap & resources Recap:  Difference between Sync and Async Event  Client API support 2 Async Events: OnLoad and OnSave  OnChange Event is Sychronous !!  Custom Enable Rules support Asynchronous operations Resources:  Docs:  https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference  https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/events/form-onsave  https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/customize-dev/define-ribbon- enable-rules?view=op-9-1#custom-rule  Demos source code:  https://gist.github.com/melamriD365/a42ff66001285cbdd07d685a6daabbee