Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Hide and show web resource with javascript code

(0) ShareShare
ReportReport
Posted on by 87

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
    87 on at
    RE: Hide and show web resource with javascript code

    It was fixed andc everything ok. Thanks

  • Suggested answer
    a33ik Profile Picture
    84,331 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
    87 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
    84,331 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
    197 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
    87 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
    87 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
    197 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
    87 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
    87 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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans