5 Replies Latest reply on Jan 26, 2010 12:34 PM by TSGal

    I want a script to delete auto an account if expired day...

    lans

      Title

      I want a script to delete auto an account if expired day...

      Post

      Hello...

      I have a layout that i add accounts...but i want a field that i put a day and if it passes this day to delete or deactivate this account automatically... 

       

       ...thanks

       

       

       

        • 1. Re: I want a script to delete auto an account if expired day...
          MikeyG79
             Maybe:  CustomFunction to check if todays date is newer than the "expiration" date - if so, set deactivated field to "Yes" or similar.
          • 2. Re: I want a script to delete auto an account if expired day...
            lans
              

            OK...but you know exactly what i must write in script...??? 

             

             ...thanks

             

            • 3. Re: I want a script to delete auto an account if expired day...
              TSGal

              lans:

               

              Thank you for your posts.

               

              Create a script that does the following:

               

               

              If [ Get ( AccountName ) = " <name of account> " ]

                 If [ Get ( CurrentDate ) > <the date field to compare> }

                    Delete Account [ <name of account> ]

                    Exit Application

                 End If

              End If

               

               

              Then, use this script as a Startup Script.  When the user logs in, the Account name is checked.  If it equals a specific account name, then compare today's date to see if it is greater than a specified date field (or constant).  If so, then delete the account (or deactivate the account) and exit FileMaker Pro.

               

              Let me know if you need clarification for any of the above steps.

               

              TSGal

              FileMaker, Inc. 

              • 4. Re: I want a script to delete auto an account if expired day...
                lans
                  

                ...Hello, tell me something...it is necessary to create this script for each user, or one script for all user...???

                 

                 very, very thanks...!!!

                 

                 

                 

                • 5. Re: I want a script to delete auto an account if expired day...
                  TSGal

                  lans:

                   

                  You will have to do this for each account you want to delete.  The first line of the script could be:

                   

                  If [ Get ( AccountName ) = " <first account name> " or Get ( AccountName ) = " <second account name> " or ......... ]

                   

                  However, if you create temporary accounts that ll begin with the same few characters, and these are different from your other accounts, you could then look at the first few characters.  For example,

                   

                  If [ Left ( Get ( AccountName ) ; 4 ) = "Temp" ]

                   

                  This looks at the first four characters, and if the AccountName starts with "Temp", then evaluate further, speeding up the process for permanent accounts.

                   

                  Since there is going to be more than one evaluation, check to see if the AccountName does NOT equal "Temp", and then you can exit the script and focus on the evaluations.

                   

                  If [ Left ( Get ( AccountName ) ; 4 ) ≠ "Temp" ]

                     Exit Script

                  End If

                   

                   

                  Now, you'll have to evaluate for each account:

                   

                  If [ Get ( AccountName ) = " <name of first account> " ]

                     If [ Get ( CurrentDate ) > ; <the date field to compare> ]

                        Delete Account [ <name of first account> ]

                        Exit Application

                     End If

                  Else If [ Get ( AccountName ) = " <name of second account> " ]

                  ...etc.

                  End If

                   

                   

                  If you are going to have a lot of temporary accounts, then you may want to put them into a table.  You can then perform a find on the table for the AccountName, evaluate the date with today's date, and if true, then delete the account.  Therefore, rather than having the above If... Else If ... End If, do the following:

                   

                  Set Error Capture [ On ]

                  Set Variable [ $acc ; Get ( AccountName ) ]

                  Go to Layout [ <layout with table containing accounts> ]

                  Enter Find Mode []

                  Set Field [ Name ; $acc ]

                  Perform Find []

                  If [ Get ( FoundCount ) > 0 ]

                     If [ Get ( CurrentDate ) > ; <Date field> ]

                        Delete Account [ $acc ]

                        (at this point you can delete record, or set value of record to old date)

                        Exit Application

                     End If

                  End If

                   

                  -------------

                   

                  Let me know if you need clarification for any of the above steps.

                   

                  TSGal

                  FileMaker, Inc.