Knack Hack: Live Connected Equation
This is a Knack tutorial for real time rendering of an equation on a form that depends on a connected object’s field. We will be using a form to create a line item for a customer and we will be calculating the total price, based on the quantity of the line item, and the price of a connected product.

Application Setup
The example application I’ll be using is an e-commerce site that allows users to add products to their account.
Create Objects
Create two objects, Product and Line Item. Create a connection between Line Item > Product.
The Product object will have fields of:
- Name (text)
- Price (currency)
- Description (paragraph text)
- Monthly (boolean)
Line Item fields:
- Product (connection to Product object)
- Quantity (number)
- Line Item Price (number)
- Total Price (equation)
- Created (date/time)
- Id (auto increment)
Create Page
Create a page with a form to insert a new Line Item. Make sure that the fields for the connected Product, quantity, and total price exist on the form.
On the same page add a table that displays Product records from your database (this will be hidden in the live app).
Custom Code
You will need to copy the following custom code to your Knack Javascript custom code editor and replace the following variables:
var scene_key = 'scene_1'
var view_key = 'view_36'
var name_field_key = 'field_1'
var price_field_key = 'field_39'
var connected_record_field_key = 'field_30'
var quantity_field_key = 'field_31'
var equation_total_field = 'field_50'In order to find the variables for your application, go to the page you have created in the builder with your form, and get the scene_key from the url. eg: `https://builder.knack.com/gavinfoster/product-app#pages/scene_1` would mean scene_1 is the value of the variable for scene_key . Similarly, to get the value of the view_key , go to the page in your builder with your form, and click on the form to edit it. You will see view key in the URL. For fields, navigate to the object where the field exists, and click on the field to edit it. You will see the field key in the URL.
If you are having trouble finding what your field, view, or scene keys are, check out the knack documentation for more in-depth help.
