How to Build an Orders App

In this tutorial, we will guide you through the necessary steps to create a basic orders app using Knack.

Use Case

In this instructional guide, we will guide you through the process of creating an Orders app using Knack.

The main feature is using a form view's record rules to copy pricing information from products into order line items. Equations and formulas are used to track quantities and totals.

Tip: To take a look at one of our sample apps similar to this build, see our Purchase Orders app.

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

1.  Define the Tables

First, we will add a Products table. This table will store all the details about each product that can be ordered, such as the Product #, Name, Price, Description, Images, etc:

Image of a Products table shown in the Knack Builder

Next, we'll add an Orders table. This table should contain details on the Order Date, Order #, and any other order information you'd like to track, such as the shipping information or any special instructions:

Image of and Orders table within the Knack Builder

Tip: You can learn more about adding and managing tables here.

 

Line Items

Lastly, we'll add a Line Items table. We'll add an auto-increment field, delete the default short text field, and include additional fields for Quantity and Price: 

Image of the Line Items table's fields in the Knack Builder

 

2.  Adding Connections

For connections, we will connect the Line Items table to both the Products and Orders tables. Each "Line Items" record will connect to a single order record and a single product record.

Note:  We will add these two connection fields to the Line Items table. To learn more about planning your connections, see our article here

 
Image of Order connection field settings in the Knack Builder
 Image of the Product connection field in the Knack Builder

 

 

3.  Adding Equations and Formulas

Next, we will proceed with adding fields to accurately calculate the total cost of each line item and sum them up for each order.

In the Line Items table, we'll add a Total equation field to multiply the price by the quantity:

Image of an Equation Field's settings for the Total

Tip: 

You can learn more about about using equation fields in our About Equations article.

Here are some additional articles for further learning on Equations:

 

In the Orders table, we will add a Sum formula to calculate the total cost of all connected line items. This formula instructs each order to locate any line items associated with that order and sum up their individual totals.

Image of the Total field's settings

Tip:  You can learn more about using formula fields here.

 

 

4.  Building the Live App

To start creating the Live App pages, we'll add a new Orders page that displays a grid view of order records. Also, we'll 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 a connected Line Item

 Image of creating the Orders page in the Knack Builder

 

Next, we'll 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 the new page, we'll add a form that adds a new Order record.

 
Image of adding a Menu view to the Orders page in the Knack Builder
 
Image of adding a Form view in the Knack Builder on the new Orders page

On the new Order form, let's 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:

Image of adding Submit Rules to the Add Order Form view

 

5.  Create a Record Rule for the Line Items Form

Lastly, we'll edit the Add Line Item form on the Order Details page. We'll delete the "Price" and "Total" inputs, and incorporate a record rule that establishes the value of the price as the price of the connected product.

By copying the price value, this price will be permanently saved. Even if you were to update the product's price in the future, the price for this line item will remain unchanged.

Image of the record rule applied to the Add Line Item form view

 

Congratulations on successfully building your Orders app! That completes the app building walk-through.

 

Extending the App

This is the fundamental functionality required for a basic order app: the ability to add Products to an Order through a Line Item record that connects them.

It is possible to further enhance this app by incorporating additional features:

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

  • Adduser 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 a workflow to track shipping and fulfillment.