locked
unable to get value of the property "setVisible" : object is null or undefined RRS feed

  • Question

  • Hello developers, I have a dropdown list with metadata name new_pctemplate. I want to hide and display sections according to users choice. I have also attached values 1,2 to the attributes of the option set so dont worry about it. The error I receive when attaching this script to the onChange event of the dropdown list is unable to get value of the property "setVisible" : object is null or undefined. What do you see wrong?

    function choosepc() {
     
        var pc= Xrm.Page.getAttribute("new_pctemplate");
     
        if (pc.getValue() == 1) {
             Xrm.Page.ui.tabs.get("Project Overview").sections.get("General1").setVisible(true);
             Xrm.Page.ui.tabs.get("Project Overview").sections.get("General").setVisible(true);
             Xrm.Page.ui.tabs.get("Customer Information").sections.get("Customer").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("VC Systems").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("System Features").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Screen").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Trolley & Cabinets").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Network services").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Support").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Other ?").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("VC System").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Screen/Display").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Trolley/Cabinet").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - PSTN").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - Router").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Installation").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("General Planning").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - BB").setVisible(true);
             Xrm.Page.ui.tabs.get("Drafts to Customer").sections.get("Drafts").setVisible(true);
             Xrm.Page.ui.tabs.get("Final Confirmation from Customer").sections.get("Confirmation").setVisible(true);
             Xrm.Page.ui.tabs.get("Installation/Training").sections.get("inst").setVisible(true);
             Xrm.Page.ui.tabs.get("Project Completion").sections.get("Completion").setVisible(true);
             Xrm.Page.ui.tabs.get("Financials").sections.get("Financials").setVisible(true);
             Xrm.Page.ui.tabs.get("Support").sections.get("Sup").setVisible(true);

         }
         if (pc.getValue() == 2) {
            Xrm.Page.ui.tabs.get("Project Overview").sections.get("General1").setVisible(true);
             Xrm.Page.ui.tabs.get("Project Overview").sections.get("General").setVisible(true);
             Xrm.Page.ui.tabs.get("Customer Information").sections.get("Customer").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("VC Systems").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("System Features").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Screen").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Trolley & Cabinets").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Network services").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Support").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Other ?").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("VC System").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Screen/Display").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Trolley/Cabinet").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - PSTN").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - Router").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Installation").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("General Planning").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - BB").setVisible(true);
             Xrm.Page.ui.tabs.get("Drafts to Customer").sections.get("Drafts").setVisible(false);
             Xrm.Page.ui.tabs.get("Final Confirmation from Customer").sections.get("Confirmation").setVisible(false);
             Xrm.Page.ui.tabs.get("Installation/Training").sections.get("inst").setVisible(false);
             Xrm.Page.ui.tabs.get("Project Completion").sections.get("Completion").setVisible(true);
             Xrm.Page.ui.tabs.get("Financials").sections.get("Financials").setVisible(true);
             Xrm.Page.ui.tabs.get("Support").sections.get("Sup").setVisible(true);
         }

    }


    aris




    Friday, August 31, 2012 11:22 AM

Answers

  • Hi Change your code like this ..

    function choosepc()
    {
    var pc = Xrm.Page.getAttribute("new_pctemplate");
    var pcValue = pc.getValue();

    if(pcValue==1)

    {
             Xrm.Page.ui.tabs.get("Project Overview").sections.get("General1").setVisible(true);
             Xrm.Page.ui.tabs.get("Project Overview").sections.get("General").setVisible(true);
             Xrm.Page.ui.tabs.get("Customer Information").sections.get("Customer").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("VC Systems").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("System Features").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Screen").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Trolley & Cabinets").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Network services").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Support").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Other ?").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("VC System").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Screen/Display").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Trolley/Cabinet").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - PSTN").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - Router").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Installation").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("General Planning").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - BB").setVisible(true);
             Xrm.Page.ui.tabs.get("Drafts to Customer").sections.get("Drafts").setVisible(true);
             Xrm.Page.ui.tabs.get("Final Confirmation from Customer").sections.get("Confirmation").setVisible(true);
             Xrm.Page.ui.tabs.get("Installation/Training").sections.get("inst").setVisible(true);
             Xrm.Page.ui.tabs.get("Project Completion").sections.get("Completion").setVisible(true);
             Xrm.Page.ui.tabs.get("Financials").sections.get("Financials").setVisible(true);
             Xrm.Page.ui.tabs.get("Support").sections.get("Sup").setVisible(true);

         }

        else if (pcValue == 2)

    {
            Xrm.Page.ui.tabs.get("Project Overview").sections.get("General1").setVisible(true);
             Xrm.Page.ui.tabs.get("Project Overview").sections.get("General").setVisible(true);
             Xrm.Page.ui.tabs.get("Customer Information").sections.get("Customer").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("VC Systems").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("System Features").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Screen").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Trolley & Cabinets").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Network services").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Support").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Other ?").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("VC System").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Screen/Display").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Trolley/Cabinet").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - PSTN").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - Router").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Installation").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("General Planning").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - BB").setVisible(true);
             Xrm.Page.ui.tabs.get("Drafts to Customer").sections.get("Drafts").setVisible(false);
             Xrm.Page.ui.tabs.get("Final Confirmation from Customer").sections.get("Confirmation").setVisible(false);
             Xrm.Page.ui.tabs.get("Installation/Training").sections.get("inst").setVisible(false);
             Xrm.Page.ui.tabs.get("Project Completion").sections.get("Completion").setVisible(true);
             Xrm.Page.ui.tabs.get("Financials").sections.get("Financials").setVisible(true);
             Xrm.Page.ui.tabs.get("Support").sections.get("Sup").setVisible(true);
         }

    }


    Note: Check weather you have given  name or lable .

    we have to give name field only.

    • Edited by Parthiban.T Friday, August 31, 2012 12:09 PM
    • Marked as answer by Aris Campeon Friday, August 31, 2012 1:49 PM
    Friday, August 31, 2012 11:55 AM
  • Hi,

       Check whether you are giving Tab Name or Tab label in (Xrm.Page.ui.tabs.get("").sections.get())

    You need to give Tab name and Section name. Only it will consider Tab/Section name not the Tab/Section label.


    Naren



    • Edited by Naren MN Friday, August 31, 2012 12:07 PM
    • Marked as answer by Aris Campeon Friday, August 31, 2012 1:49 PM
    Friday, August 31, 2012 12:06 PM
  • Hi Aris,

    I don't see any problem as such since I created sample scenario as you mentioned on change of the dropdown field, I was able to hide and show different sections in my form. There might be some tab or section name that is not being identified correctly.

    so best way to put a debugger.

    so write your code something like...

    1.

    function choosepc() {
        debugger;
        var pc= Xrm.Page.getAttribute("new_pctemplate");
      ....

    }

    2. save and publish your form.

    3. open your form and press F12 to open the debugging window of IE.

    4. go to javscript tab --> Click on Start Debugging.

    5. now change your dropdown field value.

    6. the control will go to the debugger and then you may debug line by line by pressing F10.

    7. the tab or section name line which is creating the problem will show the error there itself.

    I hope this will help you to identify the incorrect code line.

    Thanks,

    • Proposed as answer by CRMExpert Friday, August 31, 2012 1:09 PM
    • Marked as answer by Aris Campeon Friday, August 31, 2012 1:49 PM
    Friday, August 31, 2012 12:52 PM

All replies

  • Hi Change your code like this ..

    function choosepc()
    {
    var pc = Xrm.Page.getAttribute("new_pctemplate");
    var pcValue = pc.getValue();

    if(pcValue==1)

    {
             Xrm.Page.ui.tabs.get("Project Overview").sections.get("General1").setVisible(true);
             Xrm.Page.ui.tabs.get("Project Overview").sections.get("General").setVisible(true);
             Xrm.Page.ui.tabs.get("Customer Information").sections.get("Customer").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("VC Systems").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("System Features").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Screen").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Trolley & Cabinets").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Network services").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Support").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Other ?").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("VC System").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Screen/Display").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Trolley/Cabinet").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - PSTN").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - Router").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Installation").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("General Planning").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - BB").setVisible(true);
             Xrm.Page.ui.tabs.get("Drafts to Customer").sections.get("Drafts").setVisible(true);
             Xrm.Page.ui.tabs.get("Final Confirmation from Customer").sections.get("Confirmation").setVisible(true);
             Xrm.Page.ui.tabs.get("Installation/Training").sections.get("inst").setVisible(true);
             Xrm.Page.ui.tabs.get("Project Completion").sections.get("Completion").setVisible(true);
             Xrm.Page.ui.tabs.get("Financials").sections.get("Financials").setVisible(true);
             Xrm.Page.ui.tabs.get("Support").sections.get("Sup").setVisible(true);

         }

        else if (pcValue == 2)

    {
            Xrm.Page.ui.tabs.get("Project Overview").sections.get("General1").setVisible(true);
             Xrm.Page.ui.tabs.get("Project Overview").sections.get("General").setVisible(true);
             Xrm.Page.ui.tabs.get("Customer Information").sections.get("Customer").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("VC Systems").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("System Features").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Screen").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Trolley & Cabinets").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Network services").setVisible(true);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Support").setVisible(false);
             Xrm.Page.ui.tabs.get("General Order Details").sections.get("Other ?").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("VC System").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Screen/Display").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Trolley/Cabinet").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - PSTN").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - Router").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Installation").setVisible(true);
             Xrm.Page.ui.tabs.get("Planning").sections.get("General Planning").setVisible(false);
             Xrm.Page.ui.tabs.get("Planning").sections.get("Network Services - BB").setVisible(true);
             Xrm.Page.ui.tabs.get("Drafts to Customer").sections.get("Drafts").setVisible(false);
             Xrm.Page.ui.tabs.get("Final Confirmation from Customer").sections.get("Confirmation").setVisible(false);
             Xrm.Page.ui.tabs.get("Installation/Training").sections.get("inst").setVisible(false);
             Xrm.Page.ui.tabs.get("Project Completion").sections.get("Completion").setVisible(true);
             Xrm.Page.ui.tabs.get("Financials").sections.get("Financials").setVisible(true);
             Xrm.Page.ui.tabs.get("Support").sections.get("Sup").setVisible(true);
         }

    }


    Note: Check weather you have given  name or lable .

    we have to give name field only.

    • Edited by Parthiban.T Friday, August 31, 2012 12:09 PM
    • Marked as answer by Aris Campeon Friday, August 31, 2012 1:49 PM
    Friday, August 31, 2012 11:55 AM
  • Hi,

       Check whether you are giving Tab Name or Tab label in (Xrm.Page.ui.tabs.get("").sections.get())

    You need to give Tab name and Section name. Only it will consider Tab/Section name not the Tab/Section label.


    Naren



    • Edited by Naren MN Friday, August 31, 2012 12:07 PM
    • Marked as answer by Aris Campeon Friday, August 31, 2012 1:49 PM
    Friday, August 31, 2012 12:06 PM
  • No ,now I receive a msg that there isnt any function at all!! I followed the similar code many times at the past and it works for other examples. Dont know ....

    aris

    Friday, August 31, 2012 12:10 PM
  • Yes I am aware of this. For my convinience I always use the same name for label and tab/section name!

    aris

    Friday, August 31, 2012 12:18 PM
  • Yes I am aware of it! Please any other idea anyone??

    aris

    Friday, August 31, 2012 12:32 PM
  • Hi Aris,

    I don't see any problem as such since I created sample scenario as you mentioned on change of the dropdown field, I was able to hide and show different sections in my form. There might be some tab or section name that is not being identified correctly.

    so best way to put a debugger.

    so write your code something like...

    1.

    function choosepc() {
        debugger;
        var pc= Xrm.Page.getAttribute("new_pctemplate");
      ....

    }

    2. save and publish your form.

    3. open your form and press F12 to open the debugging window of IE.

    4. go to javscript tab --> Click on Start Debugging.

    5. now change your dropdown field value.

    6. the control will go to the debugger and then you may debug line by line by pressing F10.

    7. the tab or section name line which is creating the problem will show the error there itself.

    I hope this will help you to identify the incorrect code line.

    Thanks,

    • Proposed as answer by CRMExpert Friday, August 31, 2012 1:09 PM
    • Marked as answer by Aris Campeon Friday, August 31, 2012 1:49 PM
    Friday, August 31, 2012 12:52 PM
  • Hi 

    * your syntax is correct,  what type of error you are facing , and instead of giving this much condition just check with 1 or 2 condition first , and check weather itz working, 

    * Create a new Web resource and call in a new function name.

    * After that also facing same error means set debugger and check wich line you are going wrong..

    Refer Bellow link how to set debugger.

     http://social.technet.microsoft.com/wiki/contents/articles/3256.how-to-debug-jscript-in-microsoft-dynamics-crm-2011.aspx

    http://www.furnemont.eu/2010/06/how-to-series-easily-debug-your-crm-javascript-code-in-ie8/

    • Proposed as answer by CRMExpert Friday, August 31, 2012 1:09 PM
    Friday, August 31, 2012 1:08 PM
  • I only put the debugger at second line right?

    When I try to do this, at the 5th step my computer does not respond,seems to be crashing.


    aris

    Friday, August 31, 2012 1:13 PM
  • Hi Aris,

    Could you keep few lines as suggested by Parthiban and try to debug.

    Thanks,

    Friday, August 31, 2012 1:17 PM
  • Guys you were right. One of the so many sections and tabs I was using did not have a proper name in its properties and this caused the ERROR!!!

    Thank you all!


    aris

    Friday, August 31, 2012 1:49 PM