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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Why are these onLoad functions conflicting?

(0) ShareShare
ReportReport
Posted on by 283

I have two scripts each containing a function that triggers on the form onLoad event. For some reason whichever one loads second I get an error that that onLoad method does not exist. The really weird thing is that I have another script on another form with an almost identical function to the second one which loads just fine with the first function. What could be causing these two functions to conflict? Any thoughts are appreciated!

First function:

var E360 = E360 || {};
E360.Contact = E360.Contact || {};
let formContext = null;

(function () {
'use strict';
E360.Contact.onLoad = function(executionContext) {
    formContext = executionContext.getFormContext();

    //Display warning
    let dnc = formContext.getAttribute('preferredcontactmethodcode').getValue();
    let dnp = formContext.getAttribute('new_e360recruitmentengagement').getValue();
    let isMinor = formContext.getAttribute('new_isminor').getValue();

    if (dnp) {
        dnp = dnp[0].id;
        dnp = dnp.substring(1, dnp.length - 1);
    }

    if(dnp === 'A851D412-CD61-EC11-8F8F-000D3A336682') {
        formContext.ui.setFormNotification("----", 'WARNING', 'dnpWarning');
    }
    else if (dnc === 100000001) {
        formContext.ui.setFormNotification("----", 'WARNING', 'dncWarning');
    }
    else if(isMinor) {
        formContext.ui.setFormNotification("----", 'WARNING', 'minorWarning');
    }

    // Control Audit History tab
    const tabObj = formContext.ui.tabs.get("Audit History");
    const userRoles = Xrm.Utility.getGlobalContext().userSettings.roles
    const sysAdmin = userRoles.get("4f9acaa5-20c9-e811-a968-000d3a3463ea"); // System Administration role GUID

    if (sysAdmin) {
    tabObj.setVisible(true);
    }
    else {
    tabObj.setVisible(false);
    }

    //Hide BPF
    formContext.ui.process.setVisible(false);
}....
})()

Second function:

var EBI = EBI || {};
EBI.Contact = EBI.Contact || {};
let formContext = null;

(function() {
'use strict';
EBI.Contact.onLoad = function(executionContext) {
    formContext = executionContext.getFormContext();

    //Control RFI Follow-Up Tab
    const tabRfiFu = formContext.ui.tabs.get("Follow-Up Call");
    const rfiField = formContext.getAttribute('new_ebirfifurecord').getValue();

    if (rfiField) {
        tabRfiFu.setVisible(true);
    }
    else {
        tabRfiFu.setVisible(false);
    }

    // Initialize button
    const buttons = [
        formContext.getControl("WebResource_sendsmsresponsebutton"),
        formContext.getControl("WebResource_ebicallcontactbutton")
    ]
    buttons.forEach(function(button) {
        if (button) {
            button.getContentWindow().then(
                function (contentWindow) {
                    contentWindow.InitializeButton(executionContext);
                },
                function(){
                    formContext.ui.formSelector.items.get(formContext.ui.formSelector.getCurrentItem().getId()).navigate();
                }
            );
        };
    })
}.....
})()
I have the same question (0)
  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    HI Lucas,

    I would suggest to use different function name or try to combine the business logic into one function.

    Thanks,
    Pradeep

  • Lucas H Profile Picture
    283 on at

    Do you think the function name could be messing this up?

    Unfortunately, these two need to be separate functions. The first is a universal script applied to all forms and the second is a script specific to this form.

  • Lucas H Profile Picture
    283 on at

    To add to the frustration, I've reduce my first function works perfectly fine on its own but the second one throws an error no matter what I change!

    It can be totally empty and the only onLoad event and I will still get an error that the method doesn't exist:

    var EBI = EBI || {};

    EBI.Contact = EBI.Contact || {};

    let formContext = null;

    (function() {

    'use strict';

    EBI.Contact.onLoad = function(executionContext) {

    }

    })();

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans