4 Replies Latest reply on Apr 10, 2015 1:51 PM by StevenWood

    If Else statement help

    StevenWood

      Title

      If Else statement help

      Post

      I'm having some difficulty getting this to work:

      If [ (Get (CurrentDate) > (Vacation::Start Date + 179)) ]
      Set Field [ Vacation::Test container ; 0 ]
      Else If [ (Get (CurrentDate) ≥ (Vacation::Start Date + 180)) and (Get (CurrentDate) < (Vacation::Start Date + 365.24)) ]
      Set Field [ Vacation::Test container ; 40 ]
      Else If [ (Get (CurrentDate) ≥ (Vacation::Start Date + 365.25)) and (Get (CurrentDate) < (Vacation::Start Date + 730.49)) ]
      Set Field [ Vacation::Test container ; 80 ]
      Else If [ (Get (CurrentDate) ≥ (Vacation::Start Date + 730.5)) and (Get (CurrentDate) < (Vacation::Start Date + 1826.24)) ]
      Set Field [ Vacation::Test container ; 120 ]
      Else
      Set Field [ Vacation::Test container ; 160 ]
      End If

      No matter what the start date is I either get a result of 0 or 160 but nothing in between.  I have looked for examples but have found none.  I'm sure it is a simple syntax error, but I'm lost.  Also, this is the first time programming in this language so please be kind.

      Thank you.

        • 1. Re: If Else statement help
          philmodjunk

          It looks like your first expression has the wrong operator. Looks to me like you want a result of 0 if you want today's date to be less than start Date + 180 but you are using > instead of < in the first expression.

          A better way to do this might be with a single set field step with a case function used as the Calculated Result parameter:

          Let ( [ T = Get ( CurrentDate ) ;
                    V = Vacation::Start Date
                  ] ;
                   Case ( T < V + 180 ; 0 ;
                               T < V + 365.24 ; 40 ;
                               T < V + 730.49 ; 80 ;
                               T < V + 1826.24 ; 120 ;
                               160 // Else
                              ) // Case
                 ) // Let

          • 2. Re: If Else statement help
            DavidJondreau

            Phil's probably right, you may have the > mixed up. What exactly are you trying to test? Give a few examples of what the start date can be and what you're hoped-for result would be.

            Also, if the operator is correct, you save yourself a lot of trouble if you reverse the order of the Else If[]s.

             

             

             

            • 3. Re: If Else statement help
              StevenWood

              Thank you both for your help.  I'll let you know how it works out.

              • 4. Re: If Else statement help
                StevenWood

                David,

                I just reread your post.  Here's an example:

                My anniversary date for the company I work for is 04/11/12.  Therefor on the 11th of April this year I should have 3 weeks of vacation or 120 hours but until then only 2 weeks or 80 hours.  Since we subtract PTO by hours used, I want the system to update the employee's PTO record based on the current date and their anniversary date so they have the correct amount of starting hours.  However, if they haven't completed a full year they only have one week of PTO but that doesn't happen until their 6 month anniversary so the script needs to account for that.  To further complicate things it will also need at some point to recognize if they are either at or past their anniversary date and reset the amount of vacation time available since we do not bank PTO.  As they use their PTO the system will then need to remove their PTO from the amount they have available and will need to keep track of how many hours they have left.  So...ya.

                If you can think of a better way to accomplish this, I'm all ears.

                Thanks again.