Get Started
How Knack Works
Design Your Database
Manage Your Records
Build Your Live Application
View and Share Your App
Do More With Knack
Learn More
Workflow
Connect Related Data
Users & Access
Calculations & Logic
Emails & Notifications
Search & Queries
Reporting & Dashboards
E-Commerce & Payments
Builder Guide
Builder Basics
Tables & Connections
Plan Your Connections: Complex Example
Working With Tables
About Connections
Plan Your Connections: Simple Example
Connection Types
Plan Your Tables
Use Connections in Your App
Connecting Records Together
Special Tables
Connections: Troubleshooting & FAQs
Fields
Numeric Equation Functions
Field Types
Validation Rules
Date Equation Settings
Numeric Equation Settings
Formulas
Equations
Conditional Rules
Text Formulas
About Fields
Text Formula Functions
Records
CSV Format Guide for Importing
Delete Records
Import Records
Export Records
Importing Connections
Working with Records
Batch Updates
Pages
Page Menu
User Pages
Deleting a Page That's Being Linked to
Working with Pages
Navigating the Page Preview
Printing Pages & PDFs
Page Rules
Views
Grid Column Settings
Maps
Source: Which Records Will the View Display
Calendars
Grid Settings
Details
Menus
Using Action Links
Reports
Lists
Rich Text
Combining Fields from Connected Records in Views
Using Record Rules
Forms
Using Display Rules
About Views
Using Submit Rules
Searches
Grids
Users & Logins
Users and the Page Menu
Manage Roles & Permissions
Single Sign-On with Google, Facebook, Twitter, and Custom
Manage User Records
Logins and Registrations
About Users
Live App Security Settings: HIPAA Plans
Live App Security Settings
Tasks & Emails
E-Commerce
App Customization
FAQ
Support
Accounts
How do I cancel my Knack account?
I'm over the storage limit for my account. How do I add more storage or get under the limit?
Need account access or to transfer account access because account owner or colleague left the company
I'm over the record limit for my account. How do I add more records or get under the limit?
Is there an option to pay via invoice, check, wire transfer, or something other than a credit card?
How do I freeze or pause my Knack account?
Where can I find a copy of my receipt or invoice?
How do I add more API calls to my account?
Managing Apps
How do I change the favicon for my app?
How do I backup or export my apps and data?
How can I track what users are doing in my app?
How do I remove the "Powered by Knack" logo at the bottom of my app?
How do I give Builder access to a colleague or developer for one of my apps?
How do I white label my app?
How do I copy an app from my account to another account?
App Building
How do I show multiple dates on a calendar?
How do I add a logo to my app?
How do I find the most recent date from a connected table?
How do I create a field that always shows today's date?
Can I share or connect data between apps?
How do I create an "If, Then" or conditional equation?
How do I merge my apps, or copy pages, tables, or other app elements between my apps?
The menu isn't showing for my app on mobile devices. How do I fix that?
Is there a way to have new users be automatically logged-in after they register?
How do I bulk upload or import multiple files?
How do I move or copy fields or data from one table to another?
How can I show a customer's payment history if I'm collecting payments through my Knack app and through cash or check?
Is there a way to add a display rule to multiple columns at one time instead of having to update each column individually?
Do I need a separate user role table for my Vendors, Customers, Employees, Contacts, etc.?
How can I set up my app so users see only their own data?
Can I combine two date fields into a single date field? For example, combining a start and end date into a single field?
Does Knack offer a service for building apps or have developers I can hire?
How do I bulk upload or import multiple images?
How can I change the color of something in my app?
Is it possible to display more than 100 records at a time on a grid, list, or search view?
Can I?
Can I migrate or transfer data from Zoho, Quickbase, or TrackVia?
Can I add chat or messaging to my app?
Can I sell my Knack apps?
Can I use Knack on mobile devices?
Do you have a sandbox or developer environment?
Can I send SMS or text messages using Knack?
Can I integrate Knack with other data, products, and services?
Can I create invoices and accept payments?
Can I have an app in a language besides English?
Can I email PDFs or other attachments to users with Knack?
Can I add Google Analytics to my Knack app?
Can I migrate my Access, Filemaker, SQL, or other databases?
Can I prototype for others?
Can I customize the look and feel of my Knack pages?
Can I use a barcode or credit card scanner with Knack?
Other
How secure is Knack?
Does the signature captured through a signature field constitute a legally binding signature?
Does Knack offer a partner program?
How does Knack work on mobile devices? Is it mobile-friendly? Can users download my apps?
Is Knack GDPR compliant?
Storing sensitive data (credit cards, social security numbers, etc.)
Will Knack sign an NDA (Non-Disclosure Agreement)?
Which browsers do you support?
How do I batch download all of the images and files In my app?
Imports
I'm seeing an odd character when importing data. How can I get rid of it?
How do I update existing data using an import?
My import is failing or getting stuck. What do I do?
Can I undo or reverse an import?
I'm having trouble importing into a specific type of field. What can I do?
Some of my fields aren't importing correctly. How can I fix that?
I'm having trouble importing into a connection field. What can I do?
Can I import something other than data? Like tables, pages, views, etc?
My import is taking a long time. Can you take a look?
I'm getting an error when importing. What do I do?
Do the validation rules on fields trigger when importing data?
Can I schedule or automate imports?
Can my users import data from the live app, instead of going through the builder/back-end?
I am importing data for the first time. How do I do that?
Can I import data into more than one table at the same time?
How To Guides
Add Functionality to Your Live App
How To Create Discount Codes
Create an Add To Favorites Feature
How to Access Private Records Without a Login
Accept Payments in a Live App
Manage Your Records
Use an Edit Form to Create Records If They Don't Exist
Track Which User Last Updated a Record
Copy a Record Using Record Rules
Track When Records are Created and Updated
Create a Version History for Records
Use Zapier to Insert Connected Records
Work with Connected Records
How to Show Multiple Fields in Your Connection Drop-Down
Showing Parent-Child Records in the Live App
Forms
How to Create Dynamic Dropdowns in Forms
Add Read-Only Fields to a Form
How to Change the Layout of Forms
Create a Multi-Part Form
How to Allow Users to Add New Options in Forms
How to Add Instructions to a Form
How to Customize the Text on a Submit Button
How to Automatically Capture a User’s Location on a Form
How to Use URL Variables to Pre-Populate a Form
Customize Views
How to Add a Map to a Details View
How to Add Connection Links to Views
How to Add Inline Editing to a Grid
Create a Print-Friendly Invoice Page
How to Click on an Image to Go to Another Page
How to Add Groupings to a Grid
Users & Logins
Force Users to Reset Their Passwords
Save a User's Payment Method
Create a Single Login Page for Multiple User Roles
Add Read-Only Access For Users
Show Records Connected To The Logged-in User's Company Or Other Group
Show Records Connected to the Logged-in User
Create an Admin User Role to View All Records
Workflow & Automations
Add a Pipeline to Your App
Create a Registration Form with Limited Availability
Add Stages to Your App
Store Multiple Images or Files for Individual Records
Use Multiple Image Sources for a Single Image Field
Create a Button or Link that Updates a Field to a Custom Value
Notify a User That an Item is Ready for Review
Add Assignments to Your App
Using Mailchimp
Approve New Records Before Displaying Them
Workflow Tools
Add Notification & Reminder Emails to Your App
Add Status Indicators to Your App
Logic, Equations & Formulas
Start an Auto Increment Field from Any Number
Display a Message When a Deadline is Approaching
Generate Simple Numeric Barcodes Automatically
How to Set a Random ID
Calculate Age in Years from a Birthday
How To Number Line Items
Show Upcoming Birthdays
How to Extract the Start and End Dates from a Date/Time Field
How to Display Multiple Date Formats Using a Single Date Field
Reports, Queries, and Summaries
App Walkthroughs
Build an Inventory Manager App
Build a Quiz App
Build a Warehouse Manager App
Build a Member Directory
Build an Orders App
Build a Map Directory or Store Locator App
Images & Files
Manage Your Account
Manage Your Account
About Knack Accounts
Account Plans and Billing
Managing Your Apps
Managing Your Account Settings
Sharing Apps With Shared Builders
App Settings: Map Provider
Script Attack Protection: Whitelisted Custom Code Elements and Attributes
Script Attack Protection: Protected Areas
Security & Infrastructure
Security Best Practices
Knack Status
Data Locations
Builder Security Settings for All Knack Plans
Builder Two-Factor Authentication
Performance
Table of Contents
- All Categories
- How To Guides
- Add Functionality to Your Live App
- How To Create Discount Codes
How To Create Discount Codes
Updated
by Lesley
This guide uses Validation Rules and Conditional Rules to apply a percentage discount to a total when a user enters a valid code. You can work through these instructions step-by-step by adding discount code functionality to the Bakery Manager app template (add this template to your account by clicking on the link).
Scenario
The bakery sends out discount codes in their monthly newsletters. Subscribed members can take advantage of an order discount by entering the discount code prior to checkout.
Requirements
- Table: The Data section of your Builder has a table that stores records that contain the information your users will use to check out. In our example, this table is named Orders.
- Numeric field: The Orders table has a numeric field to apply the discount rate to. In our example, this is a Sum field called Order Items Total. This could be a number field, an equation field, or a formula field
- Edit form: A page set up for your Live App has an Edit Form for your Order where the user can enter a discount code.
Steps
Add discount fields to the Orders table
Add the following fields to the Orders table.
- Add a Short Text Field called Discount Code.
- This will be where the user will input the discount code before checkout.
- Add a Number Field called Discount Amount.
- This field will be used to apply the discount rate to the order total. Conditional rules will be added to this field in the next step.
- Be sure to set this field up with Decimals setup, Decimal places of 2 and a Currency format.
- Add an Equation Field (Numeric Equation Type) called Order Total.
- This field will be used to subtract the Discount Amount field from the Order Items Total field. You will enter
{Order Items Total}-{Discount Amount}
in the Equation input box. - Be sure to set up your formatting on this equation field with Decimals setup, Decimal places of 2 and a Currency format.
- This field will be used to subtract the Discount Amount field from the Order Items Total field. You will enter
- Update the Equation in the Amount Due field to be
{Order Total}-{Total Charged}
.
Add validation rules to check for valid codes
The Discount Code field needs to have Validation Rules added in order to check for a valid code. If the entered code does not match your validation rule, they will see your custom error message.
One code per order
- Click to edit the Discount Code field, click on the "Validation Rules" tab, then click the checkbox next to “Add field validation rules”.
- Add this rule:
- When “Discount Code” “is not” “LARGE-ORDER”
- Show message “This is not a valid code, please use a different one.”
Multiple codes per order
- Click to edit the Discount Code field, click on the "Validation Rules" tab, then click the checkbox next to “Add field validation rules”.
- Add these validation rules:
- When “Discount Code” “is not” “HALF-OFF”
- When “Discount Code” “is not” “LARGE-ORDER”
- Show message “This is not a valid code, please use a different one.”
Add conditional rules to set the discount amount
The Discount Amount needs Conditional Rules to apply a discount rate depending on which code was entered. Each discount code can have multiple conditions - for example if your discount also requires a total higher than $100.
You can check for different discount codes by adding multiple conditional rules. Regardless of the number rules, you must have one default rule that leaves this field blank if no valid code is entered.
- Click to edit the Discount Amount field, click on the "Conditional Rules" tab, then click the checkbox next to “Add conditional rules”.
- Add these rules:
- Rule #1
- When “Discount Code” “is” “HALF-OFF”
- Set “Discount Amount” “to a custom value” “.50”
- Rule #2
- When “Discount Code” “is” “LARGE-ORDER”
- When “Order Items Total” “is higher than” “99”
- Set “Discount Amount” “to a custom value” “.10”
- Rule #3
- Every record
- Set “Discount Amount” “to a custom value” “0”
- Rule #1
Calculate the total using an equation
Now that the percent discounted is set, it needs to be used in conjunction with a Total to calculate the order total.
- Edit the Order Total equation field and enter the following formula so it calculates the total of the order minus the discount:
{Line Items Total} - {Discount Amount}
Add discount fields to your form
In order for this to work, the Order record must exist already, so we need to use an Edit Form.
The Form can include any other Order field, but it needs the Discount Code field at the minimum. This setup works well on an Order Details page where you can add that Edit Order form easily.
- Under the Pages section in the Builder, and then under the "Customer > Orders Login" login page, you’ll see the Order Details page. Click on that page in the left bar page tree. Add a new menu that links to a form here to “Update this page’s Order”.
- Click to edit the Menu view and click the edit pencil on the newly created “Edit Order” menu button.
- Rename to “Add Discount Code” and save the changes.
- Under the menu view, click on the “Edit Order” page.
- On the page settings update the page name to “Add Discount Code” and the Page URL to “add-discount-code”.
- Check the checkbox next to “Display page in a modal popup” and click “Update Settings”.
- Back in the page preview, click to edit the “Edit Order” form.
- Remove the view title of “Edit Order” and click “Save”.
- Click the gear icon in the top right and rename the view title and view name to “Add Discount Code”.
- Remove all inputs on the form except for the Discount Code field.
- Under the Options section, rename the “Submit Button Text” to “Apply Discount Code”.
- Finally, under the Form Rules section, update the Action to “Redirect to an existing page” and choose “My Orders > Order Details”. This will ensure the page will refresh and correctly apply the Discount Code.
- Be sure to click Save Changes on this form.
Update the checkout to use the new Order Total field
In order to make sure the checkout uses this new Order Total field that will include the discount amount, the “Checkout” Payment form needs to have the Payment total field updated from the Order Items Total field to the Order Total field.
- Click on the "Checkout" page in the left bar page tree. Then, click to edit the “Checkout” Payment form view.
- Under the Settings section, change the field selected in the drop-down for "Payment total field" from “Order Items Total” to “Order Total”. Be sure to click Save Changes on the form.
- You’ll likely want to make this same switch on the Payment Summary section fields that are displayed there.
Test it out
Head on over to the Live App view of these pages and test it out!