Build a small CRM
Model contacts, list and edit them, and save changes through a workflow, all inside one Studio project.
A CRM needs three things: somewhere to keep contacts, a screen to see them, and a way to add and edit one. This walks through all three in Studio, from an empty project to a working Contacts list with a save workflow. Budget about 25 minutes.
What you'll build
- A Contacts table with a name, email, phone and company.
- A Contacts List component (Multi View) that reads the table.
- A Contact Form component (Single View) that creates a contact.
- A Set Data program and an Alert program behind the form's Save button.
- A Route that makes the list openable as a page.
Everything below can also be typed as a prompt: "A CRM with a table for contacts and a screen that lists them" gets you a first version to adjust from. See Starting a project. This tutorial builds the same shape by hand, one tab at a time.
Step 1: Create the Contacts table
Add the table
In the left tree, right-click Database and choose Create. Set Type to Table, pick a
DBS Driver (a draft project uses its own built-in database automatically), and name it
CNT - Contacts.
Add the fields
Open the table's Fields tab and use Add field for each column: CNT_Contact_Id (String,
mandatory), CNT_Name (String, mandatory), CNT_Email (String), CNT_Phone (String),
CNT_Company (String). The CNT_ prefix keeps these columns unambiguous once other tables share
the project.
Add a unique index
On the Indexes tab, add an index on CNT_Contact_Id and turn on Unique. The Contact Form
needs this to locate one exact row later.
Add a sample row
Switch to the Data tab and add one contact with real values, so the list has something to show once it's connected.
Step 2: Build the Contacts List
Add the component
Right-click Programs and choose Create. Set Type to Component, Output to
Multi View, and name it Contacts List.
Connect the Datasource
Open the Datasource tab, choose DB Table, pick CNT - Contacts, and set the filter mode to
Index so the screen loads every contact.
Bring in the fields
Open the Fields tab. With the table connected, Studio suggests CNT_Name, CNT_Email,
CNT_Phone and CNT_Company straight from the table, start with those Table fields instead of
recreating the columns by hand.
Lay out the row
Open the UI tab. Use the Insert toolbar's UI Elements or Tag tool to add a card or row, then select it and turn on For Loop in Element properties so it repeats once per contact. Bind the name, email and phone inside it to the matching fields.
Preview it
Use the play button in the UI preview toolbar to turn on Live Preview, then confirm the sample contact shows up. See Live preview and console.
Step 3: Build the Contact Form
Add the component
Right-click Programs, Create, Type Component, Output Single View, name it
Contact Form.
Add its fields
On the Fields tab, add CNT_Name, CNT_Email, CNT_Phone and CNT_Company as Table
fields sourced from CNT - Contacts.
Build the inputs
On the UI tab, add an input for each field, then select each one to open Element properties.
Use Bind to connect the input to its field with xu-bind, so typing updates the field.
Step 4: Wire the save workflow
Add a Set Data program
Right-click Programs, Create, Type Set Data, name it Save Contact. Leave crudMode
at C to create a new row. On its Fields grid, bind CNT_Name, CNT_Email, CNT_Phone and
CNT_Company as Table fields, the same way as on the table itself.
Add an Alert program
Right-click Programs, Create, Type Alert, name it Contact Saved. On its Alert tab
set Type to Success, Display to Toast, Title to "Saved", Body to "Contact saved."
Wire the Save button
Back on the Contact Form, select the Save button in the UI tab and open Workflows in Element
properties. Use Add Action to build: Loader On (UI Utils), Set Data (Database) pointed
at Save Contact with each parameter mapped to the matching form field, Call Alert (UI Utils)
pointed at Contact Saved, then Loader Off. This is the same shape as the workflow catalog's
own saving pattern: Loader On, Set Data, Alert, Loader Off.
A toast display is safe in Live Preview. A modal or browser display can surface as a native
blocking alert() inside a preview session instead. See Alert.
Step 5: Make it a page
Add a Route
Right-click Routes, Create, name it CRM. In the Routes editor, add a menu item titled
"Contacts" pointed at the Contacts List component, and set it as the default menu item.
Open the form from the list
Select an "Add contact" element on the Contacts List and give it a workflow: Add Action >
Navigation > Call Modal, pointed at Contact Form.
Check it
Turn on Live Preview, attach the console to the running session, add a contact through the form, and confirm it appears in the list without a manual refresh. See Live preview and console.