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