Apply autonumber with Form Object Function?

Apply autonumber with Form Object Function?

I have a form object function that sets the value of a date field in a collection of records (script below).

Now I would like to set the value of the ItemNumber field in each record of this collection as well...
...BUT I would like to autonumber those values so that the ItemNumber fields start at 1 and continue with 2, 3, etc. until the entire collection has been assigned an ItemNumber field value. ALSO the order of the assignments is important and should follow the order of a field called Unit which is a string field, but with numeric entries e.g. 0101, 0102,0103, etc.

If anyone could suggest some form object function code that I could add to my function I would greatly appreciate their gift.

  1. void JulMakeDeposit(Payment NeedsDeposit)
  2. {
  3.     for each NeedsDate in NeedsDeposit
  4.     {
  5.         for each NeedsDateRecord in NeedsDate
  6.         {
  7.             NeedsDateRecord.JulDepositDate = zoho.currentdate;
  8.         }
  9.     }