Build an Orders App

Scenario

This article walks you through using Knack to create an Orders app.

The main feature is using a form's Record Rules to copy pricing information from products into order line items. Equations and Formulas are used to track quantities and totals.

You can see the Purchase Orders app here.

Requirements

If this is your first time creating an app, you'll need to know some basics about adding tables, fields, pages, and views. You can start by reading our Builder Basics section. 
Other good resources can be found in our About Your Database and Working With Pages article in our knowledge base.

Steps

Define the Tables

1. Add a Products table. This stores all the details about each product that can be ordered, such as the Product #, Name, Price, Description, Images, etc:

 

2. Add an Orders table. It should contain details on the Order Date, Order #, and any other order information you'd like to track, like the shipping info or any special instructions:

 

You can read more about adding and managing tables here.

Line Items

1. Add a Line Items table. Change the first field to an auto-increment field and add additional fields for Quantity and Price:

 

 

2. Connect Line Items to both the Products and Orders tables.  Each 'Line Items' record will connect to a single order record and a single product record:

 
 

You can read more about adding connections here.

Equations and Formulas

Add fields to track the total cost of each line item and add those up for each order.

1. In the Line Items table, add a Total equation field to multiply the price by the quantity:

 

You can read more about using equation fields here.

2. In the Orders table, add a Sum formula for adding up the connected line item totals. This tells each order to find any line items connected to that order and add up the line item totals:

 

You can read more about using formula fields here.

Build the Live App

1. Add a new Orders page that displays a grid of order records. Also, add additional links to the following:

  • Edit each record with a form

  • A details page with:

    • Details page of the Order

    • Grid of connected Line Items

    • Form to add connected Line Items

 

 

2. Add an Add Order form on your new Orders page by first adding a new menu view that links to a new page. Then on that new page, add a form that adds a new Order record.

 
 

 

On that new Order form, change the Submit Rule to redirect to the Order Details page. This way, as soon as the order is submitted, you can immediately start adding line item records:

 

 

​3. Edit the Add Line Item form on the Order Details page. Delete the Price and Total inputs, and add a record rule to set the value of the Price to the connected product's price.​

​By copying the price value, this price will be "frozen" in history.  Even if you change the product's price in the future, this price will stay locked for this line item:

 

Extend the App

This is the core functionality needed for a basic order app: adding Products to an Order through a Line Item record that connects both.

You can easily extend this app to add additional features:

  • Add pages to the live app to manage the products.

  • Add ​user logins and track which user added the order.

  • Connect each product to a vendor table.

  • Add ​reports to view order totals by product, vendor, or user.

  • Add a status field to orders and include workflow to track shipping and fulfillment.