SlideShare a Scribd company logo
1 of 21
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

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

Asp.net+interview+questions+and+answers
Asp.net+interview+questions+and+answersAsp.net+interview+questions+and+answers
Asp.net+interview+questions+and+answersMohan Raj
 
Is It The Cloud, The App, Or Just Me
Is It The Cloud, The App, Or Just MeIs It The Cloud, The App, Or Just Me
Is It The Cloud, The App, Or Just MeVik Chaudhary
 
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled Grey Matter India Technologies PVT LTD
 
Loadrunner interview questions and answers
Loadrunner interview questions and answersLoadrunner interview questions and answers
Loadrunner interview questions and answersGaruda Trainings
 
Debugging lightning components-SEDreamin17
Debugging lightning components-SEDreamin17Debugging lightning components-SEDreamin17
Debugging lightning components-SEDreamin17Mohith Shrivastava
 
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)Amazon Web Services
 
Architecting Microservices in .Net
Architecting Microservices in .NetArchitecting Microservices in .Net
Architecting Microservices in .NetRichard Banks
 
Real-time Text Audio to Video PPT Converter Tablet App
Real-time Text Audio to Video PPT Converter Tablet AppReal-time Text Audio to Video PPT Converter Tablet App
Real-time Text Audio to Video PPT Converter Tablet AppMike Taylor
 
Connecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in BluemixConnecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in BluemixIBM
 
15minutesintroductiontoappdynamics1.pdf
15minutesintroductiontoappdynamics1.pdf15minutesintroductiontoappdynamics1.pdf
15minutesintroductiontoappdynamics1.pdfAnuSelvaraj2
 
Free advertising platform for businesses with IOS & Android Apps development
Free advertising platform for businesses with IOS & Android Apps developmentFree advertising platform for businesses with IOS & Android Apps development
Free advertising platform for businesses with IOS & Android Apps developmentMike Taylor
 
Free advertising platform for businesses with IOS & Android Apps development
Free advertising platform for businesses with IOS & Android Apps developmentFree advertising platform for businesses with IOS & Android Apps development
Free advertising platform for businesses with IOS & Android Apps developmentMike Taylor
 
How to integrate flurry in android
How to integrate flurry in androidHow to integrate flurry in android
How to integrate flurry in androidadityakumar2080
 
Appium understanding document
Appium understanding documentAppium understanding document
Appium understanding documentAkshay Pillay
 
Open sap ui51_week_2_unit_3_acdt_exercises
Open sap ui51_week_2_unit_3_acdt_exercisesOpen sap ui51_week_2_unit_3_acdt_exercises
Open sap ui51_week_2_unit_3_acdt_exercisesvikram sukumar
 
AppSync.org: open-source patterns and code for data synchronization in mobile...
AppSync.org: open-source patterns and code for data synchronization in mobile...AppSync.org: open-source patterns and code for data synchronization in mobile...
AppSync.org: open-source patterns and code for data synchronization in mobile...Niko Nelissen
 
OSSF 2018 - Brandon Jung of GitLab - Is Your DevOps 'Tool Tax' Weighing You D...
OSSF 2018 - Brandon Jung of GitLab - Is Your DevOps 'Tool Tax' Weighing You D...OSSF 2018 - Brandon Jung of GitLab - Is Your DevOps 'Tool Tax' Weighing You D...
OSSF 2018 - Brandon Jung of GitLab - Is Your DevOps 'Tool Tax' Weighing You D...FINOS
 
Case study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversionCase study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversionGrey Matter India Technologies PVT LTD
 

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

Asp.net+interview+questions+and+answers
Asp.net+interview+questions+and+answersAsp.net+interview+questions+and+answers
Asp.net+interview+questions+and+answers
 
Is It The Cloud, The App, Or Just Me
Is It The Cloud, The App, Or Just MeIs It The Cloud, The App, Or Just Me
Is It The Cloud, The App, Or Just Me
 
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled Case study on Movie Quiz App For IPhone and IPad –  Facebook Enabled
Case study on Movie Quiz App For IPhone and IPad – Facebook Enabled
 
Loadrunner interview questions and answers
Loadrunner interview questions and answersLoadrunner interview questions and answers
Loadrunner interview questions and answers
 
Debugging lightning components-SEDreamin17
Debugging lightning components-SEDreamin17Debugging lightning components-SEDreamin17
Debugging lightning components-SEDreamin17
 
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
 
Architecting Microservices in .Net
Architecting Microservices in .NetArchitecting Microservices in .Net
Architecting Microservices in .Net
 
Real-time Text Audio to Video PPT Converter Tablet App
Real-time Text Audio to Video PPT Converter Tablet AppReal-time Text Audio to Video PPT Converter Tablet App
Real-time Text Audio to Video PPT Converter Tablet App
 
Connecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in BluemixConnecting Xamarin Apps with IBM Worklight in Bluemix
Connecting Xamarin Apps with IBM Worklight in Bluemix
 
15minutesintroductiontoappdynamics1.pdf
15minutesintroductiontoappdynamics1.pdf15minutesintroductiontoappdynamics1.pdf
15minutesintroductiontoappdynamics1.pdf
 
AWS Step Functions
AWS Step FunctionsAWS Step Functions
AWS Step Functions
 
Free advertising platform for businesses with IOS & Android Apps development
Free advertising platform for businesses with IOS & Android Apps developmentFree advertising platform for businesses with IOS & Android Apps development
Free advertising platform for businesses with IOS & Android Apps development
 
Free advertising platform for businesses with IOS & Android Apps development
Free advertising platform for businesses with IOS & Android Apps developmentFree advertising platform for businesses with IOS & Android Apps development
Free advertising platform for businesses with IOS & Android Apps development
 
Save Azure Cost
Save Azure CostSave Azure Cost
Save Azure Cost
 
How to integrate flurry in android
How to integrate flurry in androidHow to integrate flurry in android
How to integrate flurry in android
 
Appium understanding document
Appium understanding documentAppium understanding document
Appium understanding document
 
Open sap ui51_week_2_unit_3_acdt_exercises
Open sap ui51_week_2_unit_3_acdt_exercisesOpen sap ui51_week_2_unit_3_acdt_exercises
Open sap ui51_week_2_unit_3_acdt_exercises
 
AppSync.org: open-source patterns and code for data synchronization in mobile...
AppSync.org: open-source patterns and code for data synchronization in mobile...AppSync.org: open-source patterns and code for data synchronization in mobile...
AppSync.org: open-source patterns and code for data synchronization in mobile...
 
OSSF 2018 - Brandon Jung of GitLab - Is Your DevOps 'Tool Tax' Weighing You D...
OSSF 2018 - Brandon Jung of GitLab - Is Your DevOps 'Tool Tax' Weighing You D...OSSF 2018 - Brandon Jung of GitLab - Is Your DevOps 'Tool Tax' Weighing You D...
OSSF 2018 - Brandon Jung of GitLab - Is Your DevOps 'Tool Tax' Weighing You D...
 
Case study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversionCase study on tablet application for real time video, audio and ppt conversion
Case study on tablet application for real time video, audio and ppt conversion
 

Recently uploaded

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 

Recently uploaded (20)

Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 

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