Question Status

Verified
Jennifer M asked a question on 6 Mar 2012 1:25 PM

I am using the following code to hide two tabs and show them depending on the value returned form the option set however I continue to get the error below and can not seem to find where the code is incorrect. The first function is called onload of the form and the second and third functions are called upon the change state of the noted field. (note: I am not a developer nor do I have strong javascript coding experience)

Error:

There was an error with this field's customzed event.

Field: window

Event: onload

Error: The value of the property 'hideTabSection' is null or undefined, not a Function object.

Code:

function hideTabSection() {
     var option = Xrm.Page.getAttribute(“nhs_guaranteetype”).getSelectedOption().text;
     if ((option = null) || (option == "undefined)) {
 Xrm.Page.ui.tabs.get(2).setVisible(false)
                     Xrm.Page.ui.tabs.get(1).setVisible(false)
     }

function setVisibleGuarantees() {
     var option = Xrm.Page.getAttribute(“nhs_guaranteetype”).getSelectedOption().text;
          if (option == "Performance Guarantee")
 {
 Xrm.Page.ui.tabs.get(2).setVisible(true)
                     Xrm.Page.ui.tabs.get(1).setVisible(false)
 }

function setVisibleAllotments() {
     var option = Xrm.Page.getAttribute(“nhs_guaranteetype”).getSelectedOption().text;
          if (option == "Allotments")
 {
 Xrm.Page.ui.tabs.get(1).setVisible(true)
                     Xrm.Page.ui.tabs.get(2).setVisible(false)
 }

Any help would be greatly appreciated

Reply
Suggested Answer
Jason Lattimer responded on 6 Mar 2012 1:58 PM

Can you give this a try? There were some missing curly braces and quotes.

function hideTabSection() {
    var option = Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption().text;
    if ((option = null) || (option == "undefined")) {
        Xrm.Page.ui.tabs.get(2).setVisible(false);
        Xrm.Page.ui.tabs.get(1).setVisible(false);
    }
}

function setVisibleGuarantees() {
     var option = Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption().text;
         if (option == "Performance Guarantee") 
         {
            Xrm.Page.ui.tabs.get(2).setVisible(true);
            Xrm.Page.ui.tabs.get(1).setVisible(false);
         }
}

function setVisibleAllotments() {
    var option = Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption().text;
    if (option == "Allotments") 
    {
        Xrm.Page.ui.tabs.get(1).setVisible(true);
        Xrm.Page.ui.tabs.get(2).setVisible(false);
    }
 }

Jason Lattimer
My Blog -  Follow me on Twitter -  LinkedIn

Reply
Jennifer M responded on 6 Mar 2012 2:46 PM

Thank you SO much for your help!!

Closer - Now getting Error Unable to get value of the property 'text': object is null or undefined and the tabs initially do not hide.  However if you clear the onload error you do get the proper function when the option is set in the optionset field. (ie the tabs do hide appropriately). 

I should also say that after looking at your suggestion I did combine the code into a single function and used it both onload of the form and on change of the optionlist field. I am calling the function through the event handler properties and do not have the "Pass execution context as first parameter checked nor do I have anything listed in the comma seperated list of parameters.

function hideTabSection() {
    var option = Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption().text;
    if (option == "") {
        Xrm.Page.ui.tabs.get(1).setVisible(false);
        Xrm.Page.ui.tabs.get(2).setVisible(false);
    }
 else if (option == "Performance Guarantee")
         {
            Xrm.Page.ui.tabs.get(2).setVisible(true);
            Xrm.Page.ui.tabs.get(1).setVisible(false);
         }
 else if (option == "Allotment")
    {
        Xrm.Page.ui.tabs.get(1).setVisible(true);
        Xrm.Page.ui.tabs.get(2).setVisible(false);
    }

Reply
Verified Answer
Gus Gonzalez responded on 6 Mar 2012 6:26 PM

You need to add an if statement to run the process above when guarantee type does not equal NULL, when it equals NULL you hide the tab.

I can put something for you tomorrow morning when I get to the office and don't have to write from my cellphone.

Gus Gonzalez

Dad, Husband, Engineer, 3-time Microsoft MVP, Solution Architect,  Subject Matter Expert, Speaker, Columnist  Georgia Chapter Chairman. Follow me @GusGonzalez2.

Reply
Verified Answer
Jason Lattimer responded on 6 Mar 2012 7:57 PM

You should end up with something like this...

function hideTabSection() {
    if (Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption() == null) {
        Xrm.Page.ui.tabs.get(1).setVisible(false);
        Xrm.Page.ui.tabs.get(2).setVisible(false);
    } else {
        var option = Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption().text;
        if (option == "Performance Guarantee") {
            Xrm.Page.ui.tabs.get(2).setVisible(true);
            Xrm.Page.ui.tabs.get(1).setVisible(false);
        } else if (option == "Allotment") {
            Xrm.Page.ui.tabs.get(1).setVisible(true);
            Xrm.Page.ui.tabs.get(2).setVisible(false);
        }
    }
}

Jason Lattimer
My Blog -  Follow me on Twitter -  LinkedIn

Reply
Gus Gonzalez responded on 6 Mar 2012 8:12 PM

^ that seems right!

Gus Gonzalez

Dad, Husband, Engineer, 3-time Microsoft MVP, Solution Architect,  Subject Matter Expert, Speaker, Columnist  Georgia Chapter Chairman. Follow me @GusGonzalez2.

Reply
Jennifer M responded on 7 Mar 2012 7:14 AM

Thank you both for such quick and amazing assistance. It worked like a charm.

Reply
Verified Answer
Gus Gonzalez responded on 6 Mar 2012 6:26 PM

You need to add an if statement to run the process above when guarantee type does not equal NULL, when it equals NULL you hide the tab.

I can put something for you tomorrow morning when I get to the office and don't have to write from my cellphone.

Gus Gonzalez

Dad, Husband, Engineer, 3-time Microsoft MVP, Solution Architect,  Subject Matter Expert, Speaker, Columnist  Georgia Chapter Chairman. Follow me @GusGonzalez2.

Reply
Verified Answer
Jason Lattimer responded on 6 Mar 2012 7:57 PM

You should end up with something like this...

function hideTabSection() {
    if (Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption() == null) {
        Xrm.Page.ui.tabs.get(1).setVisible(false);
        Xrm.Page.ui.tabs.get(2).setVisible(false);
    } else {
        var option = Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption().text;
        if (option == "Performance Guarantee") {
            Xrm.Page.ui.tabs.get(2).setVisible(true);
            Xrm.Page.ui.tabs.get(1).setVisible(false);
        } else if (option == "Allotment") {
            Xrm.Page.ui.tabs.get(1).setVisible(true);
            Xrm.Page.ui.tabs.get(2).setVisible(false);
        }
    }
}

Jason Lattimer
My Blog -  Follow me on Twitter -  LinkedIn

Reply
Suggested Answer
Jason Lattimer responded on 6 Mar 2012 1:58 PM

Can you give this a try? There were some missing curly braces and quotes.

function hideTabSection() {
    var option = Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption().text;
    if ((option = null) || (option == "undefined")) {
        Xrm.Page.ui.tabs.get(2).setVisible(false);
        Xrm.Page.ui.tabs.get(1).setVisible(false);
    }
}

function setVisibleGuarantees() {
     var option = Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption().text;
         if (option == "Performance Guarantee") 
         {
            Xrm.Page.ui.tabs.get(2).setVisible(true);
            Xrm.Page.ui.tabs.get(1).setVisible(false);
         }
}

function setVisibleAllotments() {
    var option = Xrm.Page.getAttribute("nhs_guaranteetype").getSelectedOption().text;
    if (option == "Allotments") 
    {
        Xrm.Page.ui.tabs.get(1).setVisible(true);
        Xrm.Page.ui.tabs.get(2).setVisible(false);
    }
 }

Jason Lattimer
My Blog -  Follow me on Twitter -  LinkedIn

Reply