Skip to content

Save Your Contacts to Address Book

Scenario

Use this example when a process should maintain a simple address book by saving form rows into a relational database and loading them back into the form later.

Prerequisites

  • permission to create processes and relational schemas
  • access to prework and postwork scripting
  • a process form that can host repeating contact rows

Steps

Create the Folder, Process, and Task

  1. Create an application folder, for example Address Book.
  2. Create a process and open it in edit mode.
  3. Rename the opening task to Definition.
  4. Add Update and Cancel actions.

Single-task process used for the address-book workflow.

Build the Form

  1. Open the form designer.
  2. Add a tabbed content control, for example Contacts.
  3. Add a table-content control inside that tab.
  4. Create the columns required for the contact rows, such as name and phone number.
  5. Set the phone field type to Telephone.

Form designer with tabbed content and table-content for contact rows.

Extend the Data Model

Add an Id field under the repeating contact structure so each contact row can be uniquely identified.

Data model editor used to add a contact identifier field.

Define the Relational Database

  1. Open the database area of the process.
  2. Create a schema such as AddressBook.
  3. Add a table such as Contacts.
  4. Define the required fields, including a unique identifier column for the contact ID.

Relational schema editor with the contacts table and typed fields.

Save the Form Data in Postwork

In the task postwork, write the submitted rows to the relational database with ImportFromXml:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
if ($WorkItem.SelectedAction == 'Update') {
    $Database.ImportFromXml({
        Parameters: {
            TargetSchema: "AddressBook",
            TargetTable: "Contacts"
        },
        XPath: "AddressBook/PersonalInformations/Personal",
        Map: function (xml) {
            this.Phone = xml.Evaluate("PhoneNumber")
        }
    });
}

This persists the rows from the XML form data into the Contacts table.

Task postwork used to import the contact rows into the database.

Load the Existing Contacts in Prework

In the task prework, load the saved rows back into the form with ExportToXml:

1
2
3
4
5
6
7
8
$Database.ExportToXml({
    TargetSchema : 'AddressBook',
    TargetTable : 'Contacts',
    XPath : 'AddressBook/PersonalInformations/Personal',
    Map : function (row) {
        row.SetValue("PhoneNumber", this.Phone)
    }
});

This makes previously saved contacts appear when the form is opened again.

Task prework used to export saved contacts back into the XML model.

Test the Address Book

  1. Commit the process changes.
  2. Start the form.
  3. Add a contact row.
  4. Select Update to save it.
  5. Open the form again and confirm the saved contact is loaded back into the table.

Address-book form with a new row being added through the table-content control.

Result

The process now behaves like a lightweight address book: it saves repeating form rows into a relational table and loads them back when the form is reopened.