8.9 Configuring data inheritance from contexts to forms
Information entered in a context can be transferred automatically to its subcontexts, its tasks and its forms. The name of a vessel, a customer, customer numbers etc. are examples of such information. It can be automatically filled out in the forms so users do not have to find and enter this information themselves in the Zegeba app. We call this time-saving “trickle-down” system for inheritance, and the data to be inherited for autofilled meta data.
Inheritance from a context to a subcontext is described in Managing: 8.3 Adding Meta Data for a context type.
Inheritance from contexts to task titles
Inheritance from a context to a task title is done through the parameter ${contextMeta.elementID}. The elementID can be found in the Context Type Editor, in the tab Meta Data. This can then be used in the Task Template Editor‘s Task Description tab.
In the example below the ID in the Context Type Editor was meta.country so in the Task Template Editor we added the parameter ${contextMeta.country}:
In the app a task for the country Mali will with this title and description setup looks like this:
Prefill from contexts to task forms
To illustrate this type of inheritance we will use the context type Vessels. There are 2 meta data values that we want to inherit from contexts to task forms: Vessel and Customer. In the Context Type editor’s “Meta Data” tab we can find the element IDs for these: meta.vessel and meta.customer:
You can of course select more that 2 values to be inherited. The form prefill of these values must then be configured in the task templates associated with the context type in order to be inherited to its tasks. The code for this is entered in the Task Template editor for each template, as described further down.
Prefill from tasks
The prefill procedure has been greatly simplified in the latest version of Zegeba. Below, you’ll find 3 different prefill instructions: for Zegeba v 4.6 and later, 4.4, and pre-4.4. You only need to read the ones that apply to your version. You can find the version your server is running the the Dashboard or the app’s About options.
Setting up prefill from tasks to forms in Zegeba 4.6 and later
In Zegeba v 4.6 we have automated the prefill procedure as follows:
- In the design of the form that should have data prefilled from the task, go the the main Form elements’ Other property tab.
- Check the option “Automatically prefill any sub element with matching data form the Task/Context” at the bottom.
When the form is opened inside the task, the system will now search for matching IDs in the task meta data and the form. If it finds e.g. the ID meta.date in the task meta data and an element in the form with ID date, it will fill the date set in the task into the form element date. And likewise for all other meta data in the task. - If the element ID in the form is not the same as the ID used in the meta data, you must go to the form element’s Other tab and enter a code to help the system match the data.The picture below shows the Other tab for an element with ID date. The meta data field has the ID meta.startDate (found in the Task Template Editor’s Meta Data tab). We then enter the date element’s Prefill ID as startDate with the prefix task.: task.startDate. You can also prefill information about the present user of the form with the prefix userInfo…
Note: If you only have a few elements to be prefilled, you can skip steps 1 and 2 above, and just select Automatic prefill… for the individual elements instead of selecting it on the main Form element. This is up to you – the result will be the same.
Setting up prefill in Zegeba v 4.4
In Zegeba v 4.4 you do not have to find the JSON codes to enter by yourself, as described in the section below this. The code has been assembled for you, and all you have to do is find it and copy it to the form design.
- In the Task Template Editor’s tab Forms, go to Advanced Settings and
press the button [Prefill Code in Form Design].
- Press the copy icon in the top left corner to copy the displayed code to the Clipboard.
- In the Designer, open the form template where this prefill code is to be used.
- Go to the main form element’s Other properties tab.
- In Prefill Data as JSON specification,
paste the code you copied in step 2 above. - In the pasted code,
replace all <element_id in form> with the actual element IDs you have used in the form design, without the <> brackets.
In the picture above, the last two ID entries may be
“id”: “vessel”,
“id”: “customer”. - Create a test task, perhaps in a context, and test that the prefill works.
If something doesn’t work it is often due to misspelt IDs in the JSON code.
Setting up prefill from task to form in Zegeba versions pre-4.4
In addition to the values inherited from the context we would also like to autofill the form with a value entered in the task details (meta data) when issuing a task, the Project Name:
The element ID for this value can be found in the Task Template editor’s tab “Task Description”. Its standard format is meta.
Using this method, we can see that the ID for Project Name is meta.projectName:
So we’re now setting up two things: prefill into a form from the context and from the task’s meta data.
Configuring the task template
- Go to Tasks in the Dashboard,
find the template that you want to use and select Edit Task Template. - Go to “Settings” and open the Code Editor.
This editor displays the code of the template being edited in JSON,
and should only be used by users who have experience in working with this kind of code.
It is described in detail in Managing: 6.9 Using the Task Template Code Editor. - In the top Task Template window we add the following code at the end:
Values fetched from the context have the ID format contextMeta.label, while those fetched from the task have IDs meta.label.
- Press [Save] when you are done.
You can copy the code here and change it to suit your context and task setup – for instance by adding more IDs to the code.
Prefill into the form
The inheritance of these values must then be configured in the forms that are used in this task template.
- Open a form in the Designer,
select the main form element and go to Properties > Other. - Check the value Prefill form with data to open its JSON window.
- Enter the prefill code on the form as shown in the picture below.
The “id” is the element ID used in the form design,
and you must use this in the “key” with task. in front.
This code, with 2 more IDs, can be copied from here, then pasted with Ctrl-V into Prefill data as JSON specification and edited to suit your own setup. You can add as many ID sections as you like.
When this is done for one form and one task template, it can be copied to other forms and templates within this context type.
To recap: the configuration described here means that when a context for a specific vessel and customer is created, and tasks with a specific project name are created for this context, the values Vessel, Customer and Project Name are automatically filled out in the forms in the app. In real life there will usually be more than 3 values inherited, so this prefill may save a lot of time and hassle when filling out forms, as well as ensuring that the information entered is absolutely correct.