Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Do multiple OnLoad functions on the same form conflict with each other?

(0) ShareShare
ReportReport
Posted on by 355

Hi,

I'm new to JavaScript and debugging client side, and I'm experiencing some issues while debugging, I'm trying to understand whether my code is incorrect or they depend on Crm configuration.

I have multiple JavaScript functions added in the Form Properties of my Entity:

Conflicts.png

So that when I load my entity record form and open the Chrome inspector, I can inspect all of them and debugging.

- First, are there any criteria to decide which of these functions will be run first (in other terms: should I worry about it?) or is totally up to the browser? I noticed that the order I added in the Form Properties doesn't matter: the function onLoad of library 2 runs first.

- Secondly, when I debug FunctionToAddFilter and do a WebApi call, as soon as I step out from the RetrievMultipleRecords asynchronous callback and press Resume Script Execution I'm redirected to the onLoad function of library 2 again. 
If I press Step over Next function I'm redirected to the Pretty-Print minified file.

Why I'm redirected to the previous file instead than being redirected inside the success/error callBackFunction? May it depend on configuration, i.e. having multiple OnLoad functions added to the same form?

This is the complete code, including the asynchronous call:


function myFunction(executionContext) {

    debugger;
    var formContext = executionContext.getFormContext();
    var collectionid = formContext.data.entity.getId();
    var fetchFilter = "";

    Xrm.WebApi.retrieveMultipleRecords("new_movie", "?$select= directorid, new_name&$filter=new_collectionid eq"   collectionid).then(

        function success(result) {
            debugger;
            for (var i = 0; i < result.entities.length; i  ) {
                    var directorid = result.entities[i]["directorid"];
                    var directoridToUpper = directorid.ToUpperCase();
                    var directoridToUpper2 = "{"   directoridToUpper   "}"; // add {} to Guid and letter capitalization                               
                    fetchFilter  = ""   directoridToUpper2   "";
            }
            fetchFilter  = "";
            formContext.getControl("new_defaultdirectorid").addPreSearch(function () {
                formContext.getControl("new_defaultdirectorid").addCustomFilter(fetchFilter);
            })
        },
        function (error) {
            debugger;
            Xrm.openAlertDialog("error: "   error.message);
        }
    );
}

  • Verified answer
    PabloCRP Profile Picture
    PabloCRP 1,088 on at
    RE: Do multiple OnLoad functions on the same form conflict with each other?

    Hi, Joel D.

    -"First, are there any criteria to decide which of these functions will be run first"

    The excecution order in dynamics firts load Native Code, then custom code from TOP to DOWN on ONLOAD.

    -"Why I'm redirected to the previous file instead than being redirected inside the success/error callBackFunction?"

    remember Xrm.WebApi.retrieveMultipleRecords is a Promise that means that the function you don't know when but sure you will get back a reponse.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans