Create Serial Number for subform rows

Create Serial Number for subform rows

Requirement

Create serial numbers or auto-numbers for subform rows when a new row is added.

Use Case

In an employee management system, an employee can add up to five dependents. It will be easy for the employees if the dependents added in the subform are numbered automatically.
 
See how it works

Steps to follow

1. Create the forms with the following details:
Form
Form Link Name
Field Type
Field Name
Field Link Name
Add Dependents
Add_Dependents
Number
S.No
S_No
Name
N ame
Name
Drop down
Relationship
Relationship
Date
Date Of Birth
Date_Of_Birth
Add Employee
Add_Employee
Name
Name
Name
Email
Official Email
Official_Email
Radio
Gender
Gender
Subform (Add Dependents)
D ependents - You can add upto 5 Dependents.
Dependents
 
Multiple fields can be added to the Add Employee form. We have added a smaller number for brevity.
 
2. Let's limit the maximum number of subform entries to be 5:
 
3. Now, let's create a workflow to disable the S.No field in the Add Dependents subform during the load of the Add Employee form.
 
4. Add the below Deluge code in the editor:
  1. disable Dependents.S_No;

5. Now, let's create a workflow to calculate the serial number for the subform rows.


6. Add the below code in the Deluge editor:
  1. //Set the number of subform rows to 0
  2. recCount = input.Dependents.count();
  3. // Inform the employee that only 5 dependents can be added
  4. if( recCount == 5 )
  5. {
  6.   alert "This is the last dependent you can add. Please note that if you want to add a dependent, you have to remove one.";
  7. }
  8. //Set the current row's S.No value to the recCount
  9. row.S_No =recCount;
When a new subform row is added, the S.No field gets populated.

See how it works

 

Points to Note

  • Auto-number fields are not allowed inside subforms, so that there is no confusions when subform records are inserted.