Search code examples
javascriptmicrosoft-dynamicsxrm

Xrm.Page.getControl works in IE 11 and returns an object but the same code in the Edge browser returns null


I've got a script which runs on page load and does the following.

===== start of js file======

var curFldCtrl = Xrm.Page.getControl("transactioncurrencyid");

function ResetFieldLayout() {

curFldCtrl.setVisible(false);

}

function OnLoad() {

ResetFieldLayout();

}

===========end js file==============

Funny thing is that this code works find in Chrome and IE11, but when I run it in Microsoft Edge, it throws an error.

There was an error with this field's customized event.

Field:window

Event:onload

Error:Unable to get property 'setVisible' of undefined or null reference.

Anyone come across this before or know why this is happening?

Thanks in advance.


Solution

  • Try placing the variable declaration inside your function.

    function ResetFieldLayout() {
    
    var curFldCtrl = Xrm.Page.getControl("transactioncurrencyid");
    curFldCtrl.setVisible(false);
    
    }
    
    function OnLoad() {
    
    ResetFieldLayout();
    
    }