Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

error in Java script while showing/hiding a tab

Posted on by 790

Hi all



i dont know what is wrong in this code to show/hide a certain tab on CASE form , please help me.



TypeError: Cannot read property 'setVisible' of null
at showhide (hungerstation-sandbox.crm4.dynamics.com/.../new_showhidtabsoncase)
at eval (eval at RunHandlerInternal (hungerstation-sandbox.crm4.dynamics.com/.../ClientApiWrapper.aspx), <anonymous>:1:1)
at RunHandlerInternal (hungerstation-sandbox.crm4.dynamics.com/.../ClientApiWrapper.aspx)
at RunHandlers (hungerstation-sandbox.crm4.dynamics.com/.../ClientApiWrapper.aspx)
at ExecuteHandler (hungerstation-sandbox.crm4.dynamics.com/.../ClientApiWrapper.aspx)
at Mscrm.TurboForm.Control.CustomScriptsManager.$Dd_1 (hungerstation-sandbox.crm4.dynamics.com/.../formcontrols.js)
at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandler (hungerstation-sandbox.crm4.dynamics.com/.../formcontrols.js)
at Mscrm.TurboForm.Control.CustomScriptsManager.executeHandlerByDescriptor (hungerstation-sandbox.crm4.dynamics.com/.../formcontrols.js)
at hungerstation-sandbox.crm4.dynamics.com/.../formcontrols.js
at hungerstation-sandbox.crm4.dynamics.com/.../global.ashx


the code is :



function showhide()
{
subjecttype = Xrm.Page.getAttribute("subjectid");
if (typeof (subjecttype) != "undefined" && subjecttype.getValue() != null)
{
if(subjecttype =="Content Upload")
{

//parent.Xrm.Page.ui.tabs.get("ContentUpload").setVisible(true);
parent.Xrm.Page.ui.tabs.get("general").sections.get("ContentUpload").setVisible(true);


}
else
{
parent.Xrm.Page.ui.tabs.get("general").sections.get("ContentUpload").setVisible(false);
}
}
}







and i am trying to hide/show the following circulated tab based on the selected subject.

2626.Untitled5.png

*This post is locked for comments

  • Verified answer
    Ahmad Saud Profile Picture
    Ahmad Saud 790 on at
    RE: error in Java script while showing/hiding a tab

    thanks a lot Ramzi

  • Mr Ramzy GHRIBI Profile Picture
    Mr Ramzy GHRIBI 345 on at
    RE: error in Java script while showing/hiding a tab

    that's why i asked you to show in alert the value ;)

  • Ahmad Saud Profile Picture
    Ahmad Saud 790 on at
    RE: error in Java script while showing/hiding a tab

    thanks a lot for your support and patience Goutam.

    i really appreciate your help.

    thanks,

  • gdas Profile Picture
    gdas 50,085 on at
    RE: error in Java script while showing/hiding a tab

    okay great  so it is a  lookup field :) , just try to reduce the code and use my code only thing you need to change the first line to get the subject.

  • Verified answer
    Ahmad Saud Profile Picture
    Ahmad Saud 790 on at
    RE: error in Java script while showing/hiding a tab

    thanks a lot.

    i knew the problem, i should use Xrm.Page.getAttribute('subjectid').getValue()[0].name

    instead of                                     Xrm.Page.getAttribute("fieldschemaname").getValue()

    thanks,

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: error in Java script while showing/hiding a tab

    Dear Ahmad,

    Please try following code to show if subject id is Content Upload and hide if any:

    function showhide()

    {

    Var subjectid = Xrm.Page.getAttribute("fieldschemaname").getValue();

    if(subjectid == "ContentUpload")

    {

    Xrm.Page.ui.tabs.get("tabname").sections.get("sectionname").setVisible(true);//to show section

    }

    else

    {

    Xrm.Page.ui.tabs.get("tabname").sections.get("sectionname").setVisible(false);//to hide section

    }

    }

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: error in Java script while showing/hiding a tab

    Hi Ahmed ,

    Its too many lines try to reduce  -

    I am assuming that subject id is your section name so try with this - 

            function showhide() {
                var subjectid = Xrm.Page.getAttribute("subjectid").getValue();
                // Make all teh section Hide 
                Xrm.Page.ui.tabs.get("general").sections.get("Document Review").setVisible(false);
                Xrm.Page.ui.tabs.get("general").sections.get("Content Upload").setVisible(false);
                Xrm.Page.ui.tabs.get("general").sections.get("OD Configuration").setVisible(false);
                Xrm.Page.ui.tabs.get("general").sections.get("Quality Check").setVisible(false);
                Xrm.Page.ui.tabs.get("general").sections.get("OrderStation Installation").setVisible(false);
                Xrm.Page.ui.tabs.get("general").sections.get("On-Boarding call").setVisible(false);
                // Show only selected Seciton
                Xrm.Page.ui.tabs.get("general").sections.get(subjectid).setVisible(true);
            }


  • Ahmad Saud Profile Picture
    Ahmad Saud 790 on at
    RE: error in Java script while showing/hiding a tab

    thanks, code is below, but i noticed that when placing "alert(Xrm.Page.getAttribute("subjectid").getValue());" at the begging of the code, the returned answer on the browser was [object Object] . this means the value of the subject is not returned to the procedure and that is why all conditions will be false.

           function showhide()

           {

               // content upload case

               if(Xrm.Page.getAttribute("subjectid").getValue() == "Content Upload")

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("Content Upload").setVisible(true);   //  Make sure  you are providing correct sectionname , tab name

               }

               else

               {

           Xrm.Page.ui.tabs.get("general").sections.get("Document Review").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OD Configuration").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("Quality Check").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OrderStation Installation").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("On-Boarding call").setVisible(false); // Make sure  you are providing correct sectionname , tab name

               }

               // Document Review case

               if(Xrm.Page.getAttribute("subjectid").getValue() == "Document Review")

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("Document Review").setVisible(true);   //  Make sure  you are providing correct sectionname , tab name

               }

               else

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("Content Upload").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OD Configuration").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("Quality Check").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OrderStation Installation").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("On-Boarding call").setVisible(false); // Make sure  you are providing correct sectionname , tab name

               }

               // OD Configuration case

               if(Xrm.Page.getAttribute("subjectid").getValue() == "OD Configuration")

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("OD Configuration").setVisible(true);   //  Make sure  you are providing correct sectionname , tab name

               }

               else

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("Document Review").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("Content Upload").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("Quality Check").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OrderStation Installation").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("On-Boarding call").setVisible(false); // Make sure  you are providing correct sectionname , tab name

               }

               // Quality Check

               if(Xrm.Page.getAttribute("subjectid").getValue() == "Quality Check")

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("Quality Check").setVisible(true);   //  Make sure  you are providing correct sectionname , tab name

               }

               else

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("Document Review").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("Content Upload").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OD Configuration").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OrderStation Installation").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("On-Boarding call").setVisible(false); // Make sure  you are providing correct sectionname , tab name

               }

               // Order Installation

               if(Xrm.Page.getAttribute("subjectid").getValue() == "OrderStation Installation")

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("OrderStation Installation").setVisible(true);   //  Make sure  you are providing correct sectionname , tab name

               }

               else

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("Document Review").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("Content Upload").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OD Configuration").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("Quality Check").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("On-Boarding call").setVisible(false); // Make sure  you are providing correct sectionname , tab name

               }

               // OnBoarding

               if(Xrm.Page.getAttribute("subjectid").getValue() == "On-Boarding call")

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("On-Boarding call").setVisible(true);   //  Make sure  you are providing correct sectionname , tab name

               }

               else

               {

                   Xrm.Page.ui.tabs.get("general").sections.get("Document Review").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("Content Upload").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OD Configuration").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("Quality Check").setVisible(false); // Make sure  you are providing correct sectionname , tab name

                   Xrm.Page.ui.tabs.get("general").sections.get("OrderStation Installation").setVisible(false); // Make sure  you are providing correct sectionname , tab name

               }

           }

  • gdas Profile Picture
    gdas 50,085 on at
    RE: error in Java script while showing/hiding a tab

    Hi Ahmed ,

    Could you please post here your code , seems the error is coming from different part of your code .

  • Ahmad Saud Profile Picture
    Ahmad Saud 790 on at
    RE: error in Java script while showing/hiding a tab

     please find below screen shot.

    thanks

    2018_2D00_06_2D00_07-14_5F00_13_5F00_47_2D00_Case_5F00_-New-Case-_2D00_-Microsoft-Dynamics-365.jpg

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans