Skip to main content

Notifications

Customer Service forum

JavaScript for hiding sections using the Title from the Subject field (Case Management)

Posted on by Microsoft Employee

Dear Community,

I'm trying to hide/show sections based on the selection made on the "subject" of a case. I understand that the subject is in fact the subject ID but what I need to do is find out the "title" from this so that I can show/hide a section.

My script as it stands is below however this produces an error:

function showHide() {

if (Xrm.Page.data.entity.attributes.get("subjectid").getValue() != null) {

           var Title= Xrm.Page.data.entity.attributes.get("subjectid").getValue()[0].name;
       }


 {
 if (Title = "A")


 {
 Xrm.Page.ui.tabs.get("general").section.get("A").setVisible(true);
 Xrm.Page.ui.tabs.get("general").section.get("B").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("C").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("D").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("E").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("F").setVisible(false);


}
 else if (Title = "B")
 {
 Xrm.Page.ui.tabs.get("general").section.get("A").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("B").setVisible(true);
 Xrm.Page.ui.tabs.get("general").section.get("C").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("D").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("E").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("F").setVisible(false);
 }

 else if (Title = "C")
 {
 Xrm.Page.ui.tabs.get("general").section.get("A").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("B").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("C").setVisible(true);
 Xrm.Page.ui.tabs.get("general").section.get("D").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("E").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("F").setVisible(false);
 }

 else if (Title = "D")
 {
 Xrm.Page.ui.tabs.get("general").section.get("A").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("B").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("C").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("D").setVisible(true);
 Xrm.Page.ui.tabs.get("general").section.get("E").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("F").setVisible(false);
 }

 else if (Title = "E")
 {
  Xrm.Page.ui.tabs.get("general").section.get("A").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("B").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("C").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("D").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("E").setVisible(true);
 Xrm.Page.ui.tabs.get("general").section.get("F").setVisible(false);
 }

 else if (Title  = "F")
 {
 Xrm.Page.ui.tabs.get("general").section.get("A").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("B").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("C").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("D").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("E").setVisible(false);
 Xrm.Page.ui.tabs.get("general").section.get("F").setVisible(true);
 }

}
}

Categories:
  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: JavaScript for hiding sections using the Title from the Subject field (Case Management)

    Hello,

    In your if statements use == instead on = like:

    else if (Title == "B")

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

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