FAQ: How to set up prefill of metadata from context and activity to a form
All data prefill is done through an activity that prefills one or more forms.
To configure a prefill function, we first need to prepare the form and the activity template for prefill.
Prepare the Form in the Designer
For prefill to work, the form element must have the correct Element ID.
- Change the Element ID for each field that should be prefilled.
- The Element ID should be easy to recognize.
Example:
- A field that shows the customer name should have the Element ID: customername
When all fields that need prefill have the correct Element IDs, save the form.
Prepare the Activity Template
When the form is ready for prefill, add one or more metadata fields to the activity template.
When you enter a Display Name for a metadata field, a Metadata ID is created automatically.
The ID will start with meta. followed by the generated name. The ID must match the Element ID used in the form designer.
Example:
- Display Name: Customer Name
- Metadata ID: meta.customername
After a metadata field has been added to an activity template and saved, its ID cannot be changed. Because of this, make sure the Display Name matches the Element ID from the designer when you create it. The Display Name can be changed later if needed.
Check the Form Mapping
Open the Forms tab in the activity template.
You will see that the metadata field has been mapped automatically. This happens when the metadata field is added to the activity.
Add the Prefill Code to the Form
After all metadata fields have been added and the Metadata IDs match the Element IDs in the form, click Copy Prefill Code.
Copy the generated code.
Next:
- Open the form you want to prefill in the designer.
- Select the main form element.
- Open the Other tab.
- Enable Prefill form with data.
- Paste the prefill code you copied.
Save and close the form, then return to the activity template.
The prefill code must be added to every form that should be prefilled.
Create an activity and test the Prefill
When this setup is complete, you can close the activity template.
Prefill will now work automatically. For example, if a customer name is entered on the activity and a new entry is created, the customer name will be filled into the form automatically.
Prefill from Context
Context prefill is also configured through the activity.
You do not need to create the same metadata field on both the activity and the context. The field only needs to exist on the context.
To set up prefill from a context, you must first add the form that will be prefilled to the activity. This allows the system to identify which metadata field in the form should be mapped to the context.
In the activity template:
- Open the Forms tab.
- Go to Advanced Form Setup.
Here you will see all metadata fields that have been created for the activity.
Click Add Mapping at the bottom of the list.
A list of all form elements will appear, together with the form template each element belongs to.
Select the element that should be mapped to the context.
After adding the mapping, only the Element ID will be shown
Next:
- Open Settings in the activity template.
- Switch to the Code Editor.
- Find the form_context_map section.
Here you will see all metadata fields for the activity.
Find the field that should be prefilled from the context and change its Metadata ID so it starts with contextMeta.
Example:
- serviceinfo → contextMeta.serviceinfo
| Before entering contextMeta. | After entering contextMeta. |
|---|---|
After making this change, switch back to the Standard Editor and open the Forms tab. Verify that the Metadata ID has been updated.
Copy the new prefill code and paste it into the form template.
When an activity is created from a context that contains the mapped metadata field, the value will automatically be prefilled into the form.
If an activity is created without a context that contains the mapped metadata field, the prefill will simply not occur. The activity and form will still work normally.
Context data must pass through the activity before it can be added to the form.
Because of this, you must:
- Add the form template to the activity.
- Map the form field as a metadata field.
- Mark that metadata field as coming from the context by changing its ID to contextMeta…
Once these steps are complete, the context data will be passed through the activity and automatically prefill the form. :::