5 Replies Latest reply on Aug 7, 2013 10:07 AM by philmodjunk

    year(get(currentdate)

    hrcap

      Title

      year(get(currentdate)

      Post

            

           Evening All
            
           I currently have an auto enter calculation that ensures carried out a check on the year entered to ensure that it is not longer that 10 years ago and is not higher than the current year.
            
           How would i add to this script so that it automatically enters in the current year? I still want the script below to work just in case the user enters in a year that is different to the current year.
            
            
           Many Thanks
            
           Hadleigh
            
            
            
           Let(
            
           @Numbers = GetAsNumber( TextFormatRemove (Filter(Self; "0123456789")));
            
            
           Case(
            
           @Numbers   <  Year(Get(CurrentDate)) - 10 or //checks that the year entered is not over 10 years ago
           @Numbers    >   Year(Get(CurrentDate))  ;  //checks that the year entered is not higher than the current year
            
           TextColor ( Self ; RGB(255; 0; 0)) ;
            
           @Numbers
            
           )
            
           )

        • 1. Re: year(get(currentdate)
          philmodjunk

               Why not use this auto-enter calculation?

               Year ( Get ( CurrentYear ) )

               And not have the user enter this data at all?

          • 2. Re: year(get(currentdate)
            hrcap

                 Hi Phil

                 I need the above script in place just in case the user is entering historic data, i.e the user maybe entering from a previous year.

                  

                 I need the script to first off enter the current year 

                  

                 and then carry out the checks as identified in my above script just incase the user changes the year

                  

                 Any help combining the two scripts would be appreciated

                  

                  

                 cheers

                  

                  

                 Hadleigh

            • 3. Re: year(get(currentdate)
              philmodjunk

                   First, this is not a script, it's a calculation. Scripts are created via Manage | Scripts. This is created in the specify calculation dialog box.

                   If I understand you correctly, you want any year entered that is a future year or more than 10 years in the past to be automatically replaced with the current year?

                   If that's what you want, you are almost there;

                   Let(
                    
                   @Numbers = GetAsNumber( TextFormatRemove (Filter(Self; "0123456789")));
                    
                    
                   Case(
                    
                   @Numbers   <  Year(Get(CurrentDate)) - 10 or //checks that the year entered is not over 10 years ago
                   @Numbers    >   Year(Get(CurrentDate))  ;  //checks that the year entered is not higher than the current year
                    
                   TextColor ( Year ( Get ( CurrentDate ) ) ; RGB(255; 0; 0)) ;
                    
                   @Numbers
                    
                   )
                    
                   )
                    
                   Another option is to use the OnObjectValidate script trigger to perform a script that checks the range and then pops up a message notifying the user of the auto-correction with an option to return and try again if this year is not the value that they should be entering.

                    

              • 4. Re: year(get(currentdate)
                hrcap

                     Thanks PhPhilip ended up using year(get(currentdate)) in the script that opened the new record layout to set the year field to the current year.

                      

                     many thanks

                      

                     Hadleigh

                • 5. Re: year(get(currentdate)
                  philmodjunk

                       Which does exactly what my original suggestion would have done. Auto-entered calculations, as long as the "Do not replace..." option is selected, will enter an initial value when the record is created, but then the user can edit the value to change the "default" value thus entered.