There are a few scenarios where you may want line numbers to start over from "1" for a group of records. For example, in an Orders app, you have one or more Line Item records that are associated with a single Order record. For each new Order, any Line Items added will start at one and increment by a value of one for additional Line Items. The Line Item incrementation will start over from one for each new Order.
This how to guide will only cover the steps required to set up the numbering of the Line Items. To set up the other parts of an Order app, such as price calculation, see our article Build an Order App.
Add Objects & Fields
Add a new object to your app called Orders.
Next, add a new object to your app called Line Items. Then, add a new number field to your Line Items object called "Item Number."
So now you will have two objects Orders and Line Items. The Line Items object will have a field called "Item Number"
Next, the Orders and Line Items objects need to be connected. Go to your Line Items object and add a connection field to Orders by clicking on the "+ Add Connection" button.
Use the default one-to-many connection type. Each Order record will connect to many Line Items and each Line Item will connect to one Order.
Add Formulas & Equations
In your Orders object, add a count formula to count up the Line Item records connected to each Order record. Call this field "Line Item Count".
In your Orders object, add an equation field called "Current Count" that calculates “Line Item Count + 1”. This equation will use the Line Item Count field in the Orders object.
Add a new page by clicking the "+Add Page" button. Choose Orders as the source object and add the following views:
A menu linked to a form that adds a new Order.
A table to display Orders
A details to view more Order fields.
A table to display Line Items connected to the Order.
A form to add a connected Line Item
Go to the Order details page and select the form view to add a new Line Item. Click on the "Form Rules" tab and go to the “Record Rules” section.
Add a new record rule by clicking the "Add Rule" button and set the following values:
Action: update this record
When: every form submission
Value: Set Item Number to - a connected value - Current Count
Now your Line Item records will be numbered separately for each Order record.