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 CRM (Archived)

Uncaught TypeError: Cannot read property 'setVisible' of null

(0) ShareShare
ReportReport
Posted on by

Hi,

I have created a button using HTML web resource then trigger some event on that button like hiding tabs, sections and grid.

below is the code:

parent.Xrm.Page.ui.controls.get('Select_Address').setVisible(false);
parent.Xrm.Page.ui.tabs.get("general").sections.get("general_section_5").setVisible(false);

But i am getting error: Uncaught TypeError: Cannot read property 'setVisible' of null.


The above code is working fine in CRM 2016 but when i was in CRM 2015 MS released some patches that's why it is not working since.Please help.

 

Note: section and tab names are correct.

*This post is locked for comments

I have the same question (1)
  • Suggested answer
    Felippe Profile Picture
    796 on at

    Right,

    Seems like your variable parent is null, or parent.Xrm.Page.ui.controls.get('Select_Address') are null.

    You can debug your code (F12 Debugger) to check your values, or post your full code, to give more information to us.

    Best Regards,

  • Habeeb-Dynamics CRM Application Developer Profile Picture
    on at

    function updateDataToBillToLoc()

    {

            //get Grid Data

             var grid =parent.Xrm.Page.getControl("Select_Address");

             //get Selected rows

             var selectedRows = grid.getGrid().getSelectedRows();  

             //get selected Row Count

             var selectedRowsCount = selectedRows.getLength();

            if (selectedRowsCount !=0)

              {                

                  //hide update button and grid control

                 document.getElementById("billToUpdateButton").style.visibility = "hidden";

                parent.Xrm.Page.ui.controls.get('Select_Address').setVisible(false);

                parent.Xrm.Page.ui.tabs.get("general").sections.get("general_section_5").setVisible(false);

                 var rowData = selectedRows.get(0).getData();

                 var entity = rowData.getEntity();

                 var attributes = entity.getAttributes();

                //fetch sub grid attribute values to variables

                  var name = attributes.get("name").getValue();

                  var line1 = attributes.get("line1").getValue();

                  var city = attributes.get("city").getValue();

                   var stateorprovince  = attributes.get("stateorprovince").getValue();

                   var postalcode = attributes.get("postalcode").getValue();

                   var data= name + "\n" +  line1 + "\n" + city + "," + stateorprovince   + " " +postalcode ;

                   parent.Xrm.Page.getAttribute("address1_name").setValue(name);

           parent.Xrm.Page.getAttribute("address1_line1").setValue(line1);

           parent.Xrm.Page.getAttribute("address1_city").setValue(city);

    parent.Xrm.Page.getAttribute("address1_stateorprovince").setValue(stateorprovince);

    parent.Xrm.Page.getAttribute("address1_postalcode").setValue(postalcode);

                  /* if (name == null || name == undefined)

                   {

                         parent.Xrm.Page.getAttribute("new_address1info").setValue("--");

                        parent.Xrm.Page.ui.controls.get('Select_Address').setVisible(false);

                        parent.Xrm.Page.ui.tabs.get("general").sections.get("general_section_5").setVisible(false);

                  return;

                  }*/

                   parent.Xrm.Page.getAttribute("new_address1info").setValue(data);    

                  parent.Xrm.Page.getAttribute("new_address1info").setSubmitMode("always");

               }

               else

               {

                      alert("No rows selected");

                }

    }

    this is the full code and the "Select_Address" is  Address grid and it is not null. I have debugged already.

  • Suggested answer
    Goutham A Profile Picture
    2 on at

    either parent.Xrm.Page.ui.controls.get('Select_Address') or parent.Xrm.Page.ui.tabs.get("general").sections.get("general_section_5") is null.

    better introduce an if loop before applying setvisible

    like if(parent.Xrm.Page.ui.tabs.get("general").sections.get("general_section_5") !=null)

    Also please change all selectors to small case.

  • Habeeb-Dynamics CRM Application Developer Profile Picture
    on at

    yeah, Thanks but this line is working in my Sandbox, same code is not working Prod.Earlier Microsoft released some patches to my Prod 2015 after that only this issue raised and after upgrading Prod to 2016 then again this is not resolved.

  • Community Member Profile Picture
    on at

    Same issue for me. Same code, set tabs visible/hidden, working in Sandbox, bot not at Prod. 

  • naZir Profile Picture
    850 on at

    You will get this error, if the field is not available or the schema name is different.

  • tayapr Profile Picture
    167 on at

    Hey There,

    I ran into the same issue as you did! It was very confusing because I could call methods from the namespace Xrm.Page.Ui.* from the browser console but not from the specific JS code I wanted to use it in.

    In my specific scenario... I was trying to call this from an async method.  What happened is when that async code was executed it didn't know about Xrm.Page (page == undefined from this async context). As a result, the code would crash with an error "Cannot read property of blah" but I could read it from the console without issue.

    Try moving your XRM.Page.* calls to outside of any async code, store these values and pass them to the method you need them in.

    Hope this helps (someone)

  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at

    Hi,

    Try using window.parent.Xrm.Page.ui.controls.get('Select_Address');

    Also if you are opening html webresource in a popup you may need to get Xrm using :  window.top.opener.Xrm.Page.ui.controls.get('Select_Address');

    Hope this helps:)

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans