5 Replies Latest reply on Mar 7, 2011 7:27 AM by james.gould

    Timestamp script problem



      Timestamp script problem


      I've got two timestamps in one table.  One created automatically for any modification and another created via a script for when a button is clicked to approve the record (button access controlled via UAC).  Both timestamps work fine.


      Now, I'm trying to write a simple script via a trigger that runs whenever the modification timestamp changes.  I want it to compare the modification timestamp to the approval timestamp and if it is after the approval, then I want it to clear two fields (ApprovedBy and ApprovalDate), and possibly replace the ApprovedBy field with some text like "Requires reapproval."


      I can't get anything to work.  Here's the basic script:


      If [Activity::ModificationTimeStamp > Activity::ApprovalTimeStamp]

         Set Field [Activity::ApprovedBy; ""]

         Set Field [Activity::ApprovalDate; ""]

      End If


      I used the Set Field function rather than Clear function as previous advice on this forum recommended that.


      I tried it on both OnObjectModify and OnObjectSave, and nothing.


      What am I doing wrong?




        • 1. Re: Timestamp script problem
             Go into Layout setup... and use OnRecordCommit.
          • 2. Re: Timestamp script problem

            OK, Phil:


            Are you familiar with that old saying, No Good Deed Goes Unpunished? It was used often when I worked for the federal government, and was always true.


            Changing that script to trigger via the layout setup OnRecordCommit worked perfectly.


            Now, once I learned about that tool, I tried something else -- and, of course, it isn't working.


            I created a tiny script to run OnRecordLoad that would insert text into the ApprovedBy field IF the record had not been approved.  That field is auto-inserted with the user name based on a button for manager approval.


            If [Activity::ApprovedBy = IsEmpty ("Requires Approval")]

            End If


            But, nothing happens when I load records.


            Thanks (again)



            • 3. Re: Timestamp script problem

              Hi Leo,


               IsEmpty ("Requires Approval")  will always return 0 


              So unless Activity::ApprovedBy happens to be 0, the If statement will always be false.


              Perhaps you need something like: If(IsEmpty(Activity::ApprovedBy))

                                                       or: If(Not IsEmpty(Activity::ApprovedBy)) 




              • 4. Re: Timestamp script problem



                Now I see what I was doing wrong.  I was trying to follow the Help page for IsEmpty, but the example is thoroughly confusing.


                I also didn't realize that IfEmpty would operate without a lead-in to the field.


                But, it's now working!



                • 5. Re: Timestamp script problem

                  As normal, I've googled my way here!

                  Just to confirm we're all on the same page, I presume the final solution is something along the lines of:


                  If[IsEmpty ( Activity::ApprovedBy )]

                      SetField [Activity::ApprovedBy ; "Requires Approval"]

                  End If