Introduction
In some cases, you may need JavaScript to run as soon as a Model‑Driven App loads—before any form is opened. This is helpful when you want to initialize global settings, load shared logic, or trigger actions that should run once per session rather than on every form.
Dynamics 365 does not provide a direct “App OnLoad” configuration in the UI, but you can achieve this by modifying the app’s customization XML. This article explains how to add and trigger a JavaScript function on the app’s OnLoad event.
Why Trigger JavaScript on App OnLoad?
Running JavaScript at the app level is useful when you need to:
- Initialize global variables or configuration
- Load shared scripts or resources
- Set up UI elements or libraries used across multiple forms
- Trigger background logic only once when the app loads
- Avoid duplicating code on several forms
This provides a clean, centralized way to manage global initialization logic.
Example Function to Trigger
You may want to run a simple function like:
function triggerJSOnAppOnload() {
alert(“Function triggered on app onload.”);
}
This can be replaced with any logic you require.
Steps to Add JavaScript on App OnLoad
Step 1: Add Your Model‑Driven App to a Solution
Exporting the unmanaged solution gives you access to the customizations.xml file.

Step 2: Export and Extract the Solution
Download the solution as a .zip and extract it locally.
Step 3: Edit customizations.xml
- Open customizations.xml
- Search for EventHandlers inside the app definition
- Add an entry like this:

<EventHandlers>
<EventHandler eventname="onload"
functionname="triggerJSOnAppOnload"
libraryname=" ssc_triggerjsonapponload"
parameters=""
enable="true" />
</EventHandlers>
- functionname → your JavaScript function
- libraryname → the name of your uploaded JS web resource
Step 4: Re‑zip the Solution and Import Back
Save changes → Re‑zip the solution → Upload to Dynamics 365.
Step 5: Publish Customizations
Publish all for the changes to take effect.
Step 6: Test
Open the Model‑Driven App:
✔ The JavaScript library loads
✔ The function runs automatically on app load
✔ Your alert or logic executes correctly

Best Practices
- Keep app‑level JavaScript lightweight to avoid slowing download time
- Avoid long‑running blocking operations
- Move repeated logic from multiple forms into this centralized function
- Document the customizations.xml change for future maintenance
- Always test the behavior across different environments
Conclusion
Adding JavaScript on the Model‑Driven App OnLoad event gives you a powerful way to run global initialization logic without modifying individual forms. Using a simple XML update, you can ensure that your script runs as soon as the app loads—and as shown in the example, even a simple:
alert(“Function triggered on app onload.”);
works perfectly.
readmore: high roi customer portal development
FAQ’s
Not directly through the UI, but you can trigger JavaScript on App OnLoad by editing the customizations.xml file inside the solution.
You add an <EventHandler> entry inside the app’s EventHandlers section in customizations.xml, referencing your JS web resource and function name.
No — App OnLoad runs once when the Model-Driven App loads, making it ideal for global initialization logic.
Yes, as long as you document the XML change and test after importing the updated solution. Always publish customizations after import.
is a software solution company that was established in 2016. Our quality services begin with experience and end with dedication. Our directors have more than 15 years of IT experience to handle various projects successfully. Our dedicated teams are available to help our clients streamline their business processes, enhance their customer support, automate their day-to-day tasks, and provide software solutions tailored to their specific needs. We are experts in Dynamics 365 and Power Platform services, whether you need Dynamics 365 implementation, customization, integration, data migration, training, or ongoing support.


