locked
Simple jscript code not firing correctly RRS feed

  • Question

  • Maybe I have been staring at this too long, but this is a simple if, else if statement.  Change the value of field 1, and auto-set fields 2 and 3.  When changing field 1, no matter what value I select, fields 2 & 3 show the value for the Field 1 value 1 no matter what field 2 & 3 values are supposed to be.

    Field 1 Value = Auto; Field 2 Value = 500;  Field 3= >250000;

    Field 1 Value = Govt; Field 2 Value = >5000; Field 3 = >1000000; but returns Field 2 Value = 500;  Field 3= >250000; the values for field 1 Value auto.

    Here is the code:

    function BusinessType_onchange()
    {
    var BusType = Xrm.Page.getAttribute("esui_industry").getValue();
    var Gas = Xrm.Page.getAttribute("esui_gasload");
    var Elec = Xrm.Page.getAttribute("esui_electricload")

    if(BusType = 661760000)
       {
          Gas.setValue(661760001);
          Elec.setValue(661760000);
       }
    else if(BusType = 661760001)
       { 
          Gas.setValue(661760002);
          Elec.setValue(661760000);
       }
    else if(BusType = 661760002)
       { 
          Gas.setValue(661760000);
       Elec.setValue(661760000);
       }   
    else if(BusType = 661760003)
       { 
         Gas.setValue(661760001);
       Elec.setValue(661760003);
       }
    else if(BusType = 661760004)
       { 
          Gas.setValue(661760000);
       Elec.setValue(661760000);
       }      
    else if(BusType = 661760005)
       { 
          Gas.setValue(661760001);
       Elec.setValue(661760000);
       }   
    else if(BusType = 661760006)
       { 
          Gas.setValue(661760001);
       Elec.setValue(661760000);
       }   
    else if(BusType = 661760007)
       { 
          Gas.setValue(661760000);
       Elec.setValue(661760000);
       }      
    else if(BusType = 661760008)
       { 
          Gas.setValue(661760000);
       Elec.setValue(661760000);
       }      
    else if(BusType = 661760009)
       { 
          Gas.setValue(661760001);
       Elec.setValue(661760000);
       }      
    else if(BusType = 661760010)
       { 
          Gas.setValue(661760002);
       Elec.setValue(661760002);
       }      
    else if(BusType = 661760011)
       { 
          Gas.setValue(661760001);
       Elec.setValue(661760002);
       }      
    else if(BusType = 661760012)
       { 
          Gas.setValue(661760002);
       Elec.setValue(661760003);
       }      
    else if(BusType = 661760013)
       { 
          Gas.setValue(661760001);
       Elec.setValue(661760001);
       }     
    else if(BusType = 661760014)
       { 
          Gas.setValue(661760000);
       Elec.setValue(661760000);
       }     
    else if(BusType = 661760015)
       { 
          Gas.setValue(661760002);
       Elec.setValue(661760001);
       }     
    else if(BusType = 661760016)
       { 
          Gas.setValue(661760000);
       Elec.setValue(661760000);
       }     
    else if(BusType = 661760017)
       { 
          Gas.setValue(661760001);
       Elec.setValue(661760000);
       }        
    else if(BusType = 661760018)
       { 
          Gas.setValue(661760002);
       Elec.setValue(661760001);
       }        
    else if(BusType = 661760019)
       { 
          Gas.setValue(661760001);
       Elec.setValue(661760000);
       }        
    else if(BusType = 661760020)
       { 
          Gas.setValue(661760001);
       Elec.setValue(661760000);
       }        
    else if(BusType = 661760021)
       { 
          Gas.setValue(661760000);
       Elec.setValue(661760000);
       }     
    else if(BusType = 661760022)
       { 
          Gas.setValue(661760001);
       Elec.setValue(661760002);
       }     
    else if(BusType = 661760023)
       { 
          Gas.setValue(661760002);
       Elec.setValue(661760001);
       }     
    else if(BusType = 661760024)
       { 
          Gas.setValue(661760000);
       Elec.setValue(661760000);
       }     
    else if(BusType = 661760025)
       { 
          Gas.setValue(661760002);
       Elec.setValue(661760000);
       }  
    else if(BusType = 661760026)
       { 
          Gas.setValue(661760003);
       Elec.setValue(661760003);
       }  
    }

    No error messages, just wrong value.  Has got to be something simple.  Any help is appreciated.


    Ken Compter

    Friday, August 23, 2013 9:53 PM

Answers

  • Ken,

    The if condition above should use '==' to compare. However, it currently uses '='

    EX: if(BusType == 661760000)

    HTH


    Mamta

    • Marked as answer by kcompter Friday, August 23, 2013 10:53 PM
    Friday, August 23, 2013 10:05 PM

All replies

  • Hi Ken,

          Best way to resolve such issue is to put Message in each else if condition. This will guide you to the cause of error. Also if you can debug the code using debugger statement as explained here.


    Hope this helps.
     
    -----------------------------------------------------------------------
     Minal Dahiya
     
    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Friday, August 23, 2013 9:57 PM
  • Ken,

    The if condition above should use '==' to compare. However, it currently uses '='

    EX: if(BusType == 661760000)

    HTH


    Mamta

    • Marked as answer by kcompter Friday, August 23, 2013 10:53 PM
    Friday, August 23, 2013 10:05 PM