相关文章推荐

2023 Release Wave 1
Check out the latest updates and new features of Dynamics 365 released from April 2023 through September 2023

  • Release Overview Guides and Release Plans
  • Dynamics 365 Release Planner
  • The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.

    FastTrack Community | FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | All TechTalks | Architecture Insights

    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.

    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,

    //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");

    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.

    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.

    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)

    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:)

    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,

    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.

    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:)

     
    推荐文章