5 Replies Latest reply on Jan 25, 2016 6:27 AM by emory_brown

    Case Function

    847Electric

      I have two fields:

      -Voltage

           -120/240v

           -120/208v

           -277/480v

      -Phase

           -1 Phase

           -3 Phase

       

      Goal: To Select Voltage from a Drop down list and have Phase Automatically know if you select this voltage its 1phase and if you select that voltage its 3 phase.

       

      Problem: When I select my the first option 120/240v nothing happens, When I select 120/208v I get 3 phase...

      Here is the code:

      Case (

      (Voltage) = "120/240v"; "1 Phase";          //Doesn't work when I select it

      (Voltage) = "120/208v"; "3 Phase";          //Works

      (Voltage) = "277/480v"; "3 Phase";          //Works            

      )

       

       

      What am I doing wrong????

      Screenshot 2016-01-25 00.59.36.png

        • 1. Re: Case Function
          bigtom

          Have you tried committing the record on Voltage modify. Sometimes the calc will not show the correct result if the entry is not committed.

           

          Confirm the text in your value list is exactly what is in the Case.

          • 2. Re: Case Function
            TorstenBernhard

            Not sure what's wrong but the Case function is ok. I put this in a calc field and it works as expected:

            Case (

            Voltage = "120/240v"; "1 Phase";

            Voltage = "120/208v"; "3 Phase";

            Voltage = "277/480v"; "3 Phase";         

            )

            Did you check for a typo in your "Voltage" value list?

            • 3. Re: Case Function
              DanielShanahan

              I would set a script trigger OnObjectSave on Voltage instead of using a calculation field for Phase.

               

              Also, you can simplify your calculation like so:

               

              If ( Voltage = "120/240v"; "1 Phase"; "3 Phase" )

               

              I know some people don't like to use the If statement, so you could also do this:

               

              Case ( Voltage = "120/240v"; "1 Phase"; "3 Phase" )

              • 4. Re: Case Function
                emory_brown

                One thing to check would be making sure the both fields are "Text" or calculations which return "Text".

                • 5. Re: Case Function
                  emory_brown

                  Great suggestion on the simplification. For those who don't like If(), in my mind it's easier to read If() rather than Case(), because I'm not looking for multiple conditions.

                   

                  Not sure why you would recommending doing the action in the GUI via triggers. That is almost never ideal, especially when a simple calculation can ensure the logic is always enforced.

                   

                  For example, if you then have to put the "Phase" field on another screen, you have to always remember to put the script trigger on the field. More steps which open yourself up to creating bugs.