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
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:
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:
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:
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.
Tip: You can learn more about connections in the following articles:
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:
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.
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
-
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.
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:
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.
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.
-
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 a workflow to track shipping and fulfillment.