Skip to main content
Dynamics 365 general forum
Answered

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

editSubscribe (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);
        }
    );
}

Attachments
  • Verified answer
    PabloCRP Profile Picture
    PabloCRP 1,086 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.

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,126 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,646 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans