web
You’re offline. This is a read only version of the page.
close
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 363

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

I have the same question (0)
  • Verified answer
    PabloCRP Profile Picture
    1,088 on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 62 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Pallavi Phade Profile Picture

Pallavi Phade 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans