Search This Blog

Saturday 4 May 2013

Numbering rows in a LiveCycle Designer table or repeating subform

Problem

In a dynamic form rows can be added and deleted from a table, but if there is a calculated sequence number then all rows may need to be recalculated depending on where the row was inserted or deleted.

Solution

Using the XFA form dependency tracking for calculate event scripts we can easily recalculate the sequence number with two lines of JavaScript.

Detailed explanation

In the calculate event of cell in the table we can add the following code;

var count = _detail.count;
detail.index + 1;

The purpose of the first line "var count = _detail.count;" is to add _detail.count to the dependency list for this calculation event.  We don't use this value in the script but this means that whenever a row is added or removed all the calculate events on all the rows will fire, generating the correct sequence number if a row is deleted in the middle.

Using _detail, with the underscore,  is a shortcut form of referencing the detail.instanceManager, I could have written this line of code as "var count = detail.instanceManager.count;" and in this case it doesn't really matter but generally I use the underscore syntax as it works even when there are no rows.

LiveCycle Designer Forms support XSLT 1.0 and in this sample is an example of using XSLT to generate an alphabetic sequence and a roman number sequence.



Download sample form AutoNumber.pdf
 

4 comments:

  1. Numbering rows in a LiveCycle Designer table or repeating subform where is the pdf?

    ReplyDelete
  2. Hi Laila, Seems Google doesn't want attachments in Google Sites anymore. Have moved to Google Drive, so the "Download sample form AutoNumber.pdf" is working again.

    Regards
    Bruce

    ReplyDelete
  3. Many many Thanks. I get this pdf now.

    ReplyDelete
  4. Thank you for this, It has helped me a lot!

    ReplyDelete