Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Hide and show web resource with javascript code

Posted on by 85

I create 2 webresource and I want when the item of field (option set type) was chosen one of webresource hide.

2018_2D00_06_2D00_13_5F00_17_2D00_07_2D00_38.png

Field name: ClientType

Webresource1: GreenColor

Webresource2: RedColor

2018_2D00_06_2D00_13_5F00_17_2D00_07_2D00_38.png

I don't know the javascript code to fix this problem.

*This post is locked for comments

  • Amin Barek Profile Picture
    Amin Barek 85 on at
    RE: Hide and show web resource with javascript code

    It was fixed andc everything ok. Thanks

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Hide and show web resource with javascript code

    I can repeat - everything depends on the logic you want to implement. I believe that if value is null all the webresources should be hidden and code I provided in previous reply works fine. If you need something else - I don't have telepathic skills to read your mind.

  • Amin Barek Profile Picture
    Amin Barek 85 on at
    RE: Hide and show web resource with javascript code

    what about the null condition? what is the code?

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Hide and show web resource with javascript code

    If you have null it's up to you to decide what logic to apply. As for me you don't need that huge if..else sequence. Check how your code can look like without it:

    function SetFieldInvisibleByVlaue(){
    	var ClientType= Xrm.Page.getAttribute("new_khoshhesabi").getValue();
    	Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(ClientType == "1");
    	Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(ClientType == "3");
    	Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(ClientType == "2");
    }


  • Gaurav_Pandey09 Profile Picture
    Gaurav_Pandey09 195 on at
    RE: Hide and show web resource with javascript code

    That is the fourth condition so you will have a structure of this sort :

    function SetFieldInvisibleByVlaue(){

    var ClientType= Xrm.Page.getAttribute("new_khoshhesabi").getValue();

    if (ClientType == 1){          

    Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(true);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);

    }

    else if (ClientType== 2){

    Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false); Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(true);

    }

    else if (ClientType== 3){

    Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false); Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(true);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);

    }

    else{

    //Null logic goes here

    }

    }

    With just else you don't give condition. It will go there if all your above conditions doesn't meet.

    Another good practice is to check for null in the first step itself.

    Please be attentive while checking your condition

    Cheers,

    Gaurav

  • Amin Barek Profile Picture
    Amin Barek 85 on at
    RE: Hide and show web resource with javascript code

    function SetFieldInvisibleByVlaue(){

    var ClientType= Xrm.Page.getAttribute("new_khoshhesabi").getValue();

    if (ClientType == "1"){          

    Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(true);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);

    }

    else if (ClientType== "2"){

    Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(true);

    }

    else ClientType== "3"){

    Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(true);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);

    }

    }

  • Amin Barek Profile Picture
    Amin Barek 85 on at
    RE: Hide and show web resource with javascript code

    Do you mean:

    function SetFieldInvisibleByVlaue(){

    var ClientType= Xrm.Page.getAttribute("new_khoshhesabi").getValue();

    if (ClientType == "1"){          

    Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(true);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);

    }

    else if (ClientType== "2"){

    Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(true);

    }

    else ClientType== "3"){

    Xrm.Page.ui.tabs.get("tab_3").sections.get("details_tab_section_7").setVisible(false);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_5").setVisible(true);

    Xrm.Page.ui.tabs.get("tab_3").sections.get("summary_tab_section_6").setVisible(false);

    }

    }

    And when I had a null condition what can I do?

  • Gaurav_Pandey09 Profile Picture
    Gaurav_Pandey09 195 on at
    RE: Hide and show web resource with javascript code

    Hi Amin,

    It goes kike this:

    if(condition1){

    }

    else if(condition2){

    }

    else{

    }

    Cheers,

    Gaurav

  • Amin Barek Profile Picture
    Amin Barek 85 on at
    RE: Hide and show web resource with javascript code

    If we had 3 condition what should to do? If ---- else If ----- else if ???

  • Amin Barek Profile Picture
    Amin Barek 85 on at
    RE: Hide and show web resource with javascript code

    I checked ...... Completely worked

    Thanks

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