Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Java Script on Form Error on First Load of Form Only

$
0
0

I am trying to add some java code to control visibility of certain tabs on a particular form in CRM.  I will preface my question by stating up front that I am not experienced at all with Java, & that I used an outside consulting firm's code from another form as my starting point.  I have the following code on a form in CRM- & it will work as intended EXCEPT the first time that I open the form.  I get the following error with the initial form load:

....here is the code:

Form_onload = function () {

    var CRM_FORM_TYPE_CREATE = 1;
    var CRM_FORM_TYPE_UPDATE = 2;

    /*--------------------------------------------------------------------
    START new_clientcontractstatus OnChange
    ---------------------------------------------------------------------*/
  HideTabByLabel("Contract Information", "collapsed", true);
                HideTabByLabel("Terminations", "expanded", true);
         HideTabByLabel("Level of FEG Investment Discretion", "expanded", true);
    new_clientcontractstatus_Onchange = function () {
       
 //determine if combo box clientcontractstatus is null...doesn't updated anything if is null (line #38)

  if (Xrm.Page.getAttribute("new_clientcontractstatus").getSelectedOption() != null) {


            var requesttype = Xrm.Page.getAttribute("new_clientcontractstatus").getSelectedOption().text;

            if (requesttype == "New Client") {
              
                HideTabByLabel("Contract Information", "expanded", false);
                HideTabByLabel("Terminations", "expanded",true);
  HideTabByLabel("Level of FEG Investment Discretion", "expanded", false);
  }        
              
     

       else  {

  HideTabByLabel("Contract Information", "collapsed", false);
                HideTabByLabel("Terminations", "collapsed",true);
  HideTabByLabel("Level of FEG Investment Discretion", "expanded", false);
  } 

}
}

    Xrm.Page.getAttribute("new_clientcontractstatus").addOnChange(new_clientcontractstatus_Onchange);
    Xrm.Page.getAttribute("new_clientcontractstatus").fireOnChange();
    /*--------------------------------------------------------------------
    END new_clientcontractstatus OnChange
    ---------------------------------------------------------------------*/
}

...I am pretty sure that the syntax I am using is causing the addOnChange event for my field to not be recognized with the initial load of the form.  If I subsequently try to load the form again it will work as intended.  Any assistance on what I am missing would be greatly appreciated!!


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>