Time Lapsed since Last Record meeting criteria - script Question

Time Lapsed since Last Record meeting criteria - script Question

I figured out the problem and found a solution: The  sort by Added_Time desc; actually calls the record you are creating, so if you really want the last record before that you need to insert the criteria ID<input.ID (as shown in the corrected code below).

  1. test = input.Person;
  2. LastRecThisPerson  =  ThisForm  [(Person = test && ID < input.ID && Added_Time == today)] sort by  Added_Time desc;
  3. if (LastRecThisPerson.ID  ==  null)
  4. {
  5.     input.LapsedTimeInHours = 0.00;
  6. }
  7. if (LastRecThisPerson.ID  >  100)
  8. {
  9.     input.LapsedTimeInHours = ((zoho.currenttime - LastRecThisPerson.Added_Time)  /  1000  /  60  /  60);
  10. }