Scenario
Your app displays a list of records from your database. You want users to be able to create new records, but you want to review and approve each new record before it will display on your list.
Example: A "Community Events" app displays a list of community events. There's a form for the community to submit a new event for the app to display.
Requirements
You'll need to activate users in your app. You'll also need to set the user settings to have logins for different pages and user roles. This article will show you how: About Users.
If this is your first time creating an app, you'll need to know some basics about adding objects, fields, pages, and views. You can start by watching our "Introducing Knack" video tour and then working through the articles in our Builder Basics section. Other good resources can be found in our designing the database and building pages sections of the knowledge base.
Steps
This example will use a "status" field to limit which records a view can display. New records added by users will not be approved by default, and they can only view records that have been approved.
A new administrative page is then added to review records and update the "Approved" to "Yes".
Add a Field to Store a "Status"
Find the object that stores your records in the Data section of the builder. In this example, this is the "Events" object.
Add a new "Yes/No" field using the “Choice” selection in the top menu; we’ll call it “Approved”:
Knack Tip: This field will default new records to "No". If you have existing records, make sure to update to the new Approved value for those. Use a batch update to update them all at once.
Add a Form for Submitting a New Record
If you don't have one, add a form for your users to submit a new Event.
Access your Pages builder and add a new page.
After selecting whether you want to require a login or not, click the Continue button and select the "Events" object when prompted.
When selecting the views, make sure only the third option is selected. We’ll call this page "Submit an Event".
Edit the form by clicking on it and make sure the "Approval Status" field is deleted from the group of form inputs. Otherwise, the submitter would be able to set that Approved value.
Add a Page to View and Approve Records
From the "Pages" builder, add a new page that requires a login. The login should be restricted to a higher-level role that not all users have access to. In this example, this is a user role called “Super Admin”.
Similar to the second step, after clicking "Continue", select the “Events” object.
For this example, only the second view preset is required. We want a table with a link to edit an event record. We’ll call this page "Approve Events".
This page will only display records with an "Approved" value of No. Since that’s the default for new records, this table will now show any records that haven't been approved yet.
In order to do accomplish this, we need to edit the Data Source of our new table. Edit the new table by clicking on it, then access the "Data Source" tab in the left menu.
Click on the "add a new filter" link and add a filter that says “Approved” “is” “No”:
Update your view to show approved records only
In your "Pages" builder, locate the page with the public table or calendar that displays the “Event” records. If you don’t have one, you can follow the previous step again without applying the login restriction.
Edit the table by clicking on it, then access the "Data Source" tab in the left menu.
This time, add a filter that says "Approved" “is” “Yes”. Now the view will only display records that have been approved by someone with higher access.
Notes
-
If you need more complex workflows, you could use a Multiple Choice field instead of a Yes/No field. Include at least two options: "Pending Approval" and "Approved".
-
If you have existing records, make sure to update the new "Approved" value for those. Use a batch update to update them all at once.
-
Track who made updates by adding a form rule to connect the record to the logged-in user. You could also update a "Date Approved" field with a form rule to track when it was approved.