5 Replies Latest reply on Feb 22, 2015 7:09 AM by SteveMartino

    Cannot get script to work with drop down box

    danlee

      Title

      Cannot get script to work with drop down box

      Post

      I have a drop down box with choices, Weight Loss and Weight Gain.  If user chooses Weight Loss one calculation occurs.  If they choose Weight Gain a different calculation occurs.  Right now if they choose Weight Loss the correct calculation occurs.  But if they choose Weight Gain the field comes out empty.  Please help!!

      Case ( Clients::Weight Loss_Gain = "Weight Loss" ;

      (Case ( not IsEmpty ( ActivityLevelPossibleDelete ) ; Max ( Case ( ActivityLevelPossibleDelete = "Sedentary" ;(1.2 * BMRCalculator) - 500;
      ActivityLevelPossibleDelete = "Lightly Active (1-3 days/week)";(1.375 * BMRCalculator) - 500;
      ActivityLevelPossibleDelete = "Moderate (3-5 days/week)" ;(1.55 * BMRCalculator) - 500;
      ActivityLevelPossibleDelete = "Very Active (6-7 days a week)" ;(1.725 * BMRCalculator)-500) ; 1200 ); 

      Clients::Weight Loss_Gain = "Weight Gain" ;

      Case ( not IsEmpty ( ActivityLevelPossibleDelete ) ; Max ( Case ( ActivityLevelPossibleDelete = "Sedentary" ;(1.2 * BMRCalculator) + 200;
      ActivityLevelPossibleDelete = "Lightly Active (1-3 days/week)";(1.375 * BMRCalculator) + 200;
      ActivityLevelPossibleDelete = "Moderate (3-5 days/week)" ;(1.55 * BMRCalculator) + 200;
      ActivityLevelPossibleDelete = "Very Active (6-7 days a week)" ;(1.725 * BMRCalculator) + 200) ; 1500 ) )

       ) ) ) 

        • 1. Re: Cannot get script to work with drop down box
          philmodjunk

          A possible explanation consistent with what you describe is that the value you select from the value list for specifying "Weight Gain" is at least one character different from the text your calculation specifies in quotes in the Case function. This might be something such as a trailing space after the "n" in "Gain" so this may not be an easy difference to spot.

          • 2. Re: Cannot get script to work with drop down box
            danlee

            That does not seem to be the case.  There is something in the calculation that I am doing correctly.  Any other suggestions?  Thank you.

            • 3. Re: Cannot get script to work with drop down box
              SteveMartino

              What kind of field is the dropdown?  Global?  Try a Set Variable in the first script step to see if the dropdown field is indeed selected.  I can't test this because I'm on my iPad, but it seems the way your parethesis are set up doesnt allow you to check for "Weight Gain". Try this in a duplicate script;

              Case ( 
                         Clients::Weight Loss_Gain = "Weight Loss" ;
                                        Case ( 
                                                    not IsEmpty ( ActivityLevelPossibleDelete ) ; Max ( 
                                                                                                                                     Case ( 
                                                                                                                                                ActivityLevelPossibleDelete = "Sedentary" ;(1.2 * BMRCalculator) - 500;
                                                                                                                                                ActivityLevelPossibleDelete = "Lightly Active (1-3 days/week)";(1.375 * BMRCalculator) - 500;
                                                                                                                                                ActivityLevelPossibleDelete = "Moderate (3-5 days/week)" ;(1.55 * BMRCalculator) - 500;
                                                                                                                                                ActivityLevelPossibleDelete = "Very Active (6-7 days a week)" ;(1.725 * BMRCalculator)-500 ; 1200 
                                                                                                                                                ) 
                                                                                                                                     )
                                                    );

              //Clients::Weight Loss_Gain = "Weight Gain" ;  not needed if you're only choices are "Weight Loss" & "Weight Gain"

                         Case ( 
                                    not IsEmpty ( ActivityLevelPossibleDelete ) ; Max ( 
                                                                                                                       Case ( 
                                                                                                                                   ActivityLevelPossibleDelete = "Sedentary" ;(1.2 * BMRCalculator) + 200;
                                                                                                                                   ActivityLevelPossibleDelete = "Lightly Active (1-3 days/week)";(1.375 * BMRCalculator) + 200;
                                                                                                                                   ActivityLevelPossibleDelete = "Moderate (3-5 days/week)" ;(1.55 * BMRCalculator) + 200;
                                                                                                                                   ActivityLevelPossibleDelete = "Very Active (6-7 days a week)" ;(1.725 * BMRCalculator) + 200) ; 1500 
                                                                                                                                   )
                                                                                                                    )
                                    )
                      )

              • 4. Re: Cannot get script to work with drop down box
                danlee

                This time it calculates the Weight Gain if the user chooses that from the dropdown list but not the Weight Loss.  I actually get a "?" in the calculation field when Weight Loss is chosen

                • 5. Re: Cannot get script to work with drop down box
                  SteveMartino

                  If it were me, I would be to put the formula into the data viewer.  I would take out everything under "Weight Loss" part of case statement and have it return a "True" for true. Then I would start adding back in pieces and checking to see if it gets past the first nested Case, then the max, then the last nested case.