Import module
đ Descriptionâ
The Import
module contains helper functions for importing data into forms. This is useful for prefilling forms.
Read the Prefilling forms guide for more information.
đ Functions overviewâ
The following table shows the available data import functions and a description of what they do:
Function | Description |
---|---|
fields | Imports data into the form fields. This is the de facto function for importing data into a form. |
CSV | Import data into a form using CSV input. |
values | Import raw data values into the form. |
đŠâđģ Exampleâ
import { run } from "@tripetto/runner-autoscroll";
import { Import } from "@tripetto/runner";
run({
definition: /* Supply your form definition here */,
onImport: (instance) => {
// This example assumes the form has two text fields with
// the data identifiers (aliases) `FIRSTNAME` and `LASTNAME`.
Import.fields(instance, [
{
name: "FIRSTNAME",
value: "John",
},
{
name: "LASTNAME",
value: "Doe",
}
]);
// Or use the generated key of each field
Import.fields(instance, [
{
key: "9ef64ab160ef6096ceecb4561f3eecc37007b669337929393a9d3789fa744f3e",
value: "John",
},
{
key: "e14599867b9fd518459e7ecaf974d33f84f2c3b322f644e838f948c2136eec3a",
value: "Doe",
}
]);
}
});
âļī¸ Functionsâ
đ§ CSV
â
Imports data values using a CSV record. The number of columns in the CSV record and their order should exactly match the number of fields and their order in the instance.
Signatureâ
CSV(
instanceOrContext: Instance | Context,
record: string,
selection?: string[],
delimiter?: string
): boolean
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
instanceOrContext | Instance | Context | No | Reference to the instance or context. |
record | string | No | Specifies the CSV record string to import. |
selection | string[] | Yes | Specifies the identifiers of the slots that should be imported. |
delimiter | string | Yes | Specifies the delimiter for the CSV input (default is , ). |
Return valueâ
Returns true
if the import succeeded or false
when the import failed (probably because the column and field count are not equal).
You can use the CSV
export function to retrieve a sample CSV record for a form definition.
đ§ fields
â
Import data fields to the supplied form instance. You can import the fields by referencing the unique key of the field or by specifying the name of the field.
Signatureâ
fields(
instanceOrContext: Instance | Context,
fields: (IFieldByKey | IFieldByName)[],
selection?: string[],
separator?: string
): boolean
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
instanceOrContext | Instance | Context | No | Reference to the instance or context. |
fields | (IFieldByKey | IFieldByName )[] | No | Contains the fields to import. You can reference a field by its key or field name. |
selection | string[] | Yes | Specifies the identifiers of the slots that should be imported. |
separator | string | Yes | Specifies the string that is used to separate subject and field names for slots that are part of an iteration (default is / ). |
Return valueâ
Returns true
if the import succeeded or false
when there was an error and one or more of the specified fields could not be imported.
Exampleâ
import { run } from "@tripetto/runner-autoscroll";
import { Import } from "@tripetto/runner";
run({
definition: /* Supply your form definition here */,
onImport: (instance) => {
// This example assumes the form has two text fields with
// the data identifiers (aliases) `FIRSTNAME` and `LASTNAME`.
Import.fields(instance, [
{
name: "FIRSTNAME",
value: "John",
},
{
name: "LASTNAME",
value: "Doe",
}
]);
// Or use the generated key of each field
Import.fields(instance, [
{
key: "9ef64ab160ef6096ceecb4561f3eecc37007b669337929393a9d3789fa744f3e",
value: "John",
},
{
key: "e14599867b9fd518459e7ecaf974d33f84f2c3b322f644e838f948c2136eec3a",
value: "Doe",
}
]);
}
});
đ§ values
â
Import data values to the instance.
Signatureâ
values(instanceOrContext: Instance | Context, values: IValues, selection?: string[]): boolean
Parametersâ
Name | Type | Optional | Description |
---|---|---|---|
instanceOrContext | Instance | Context | No | Reference to the instance or context. |
values | IValues | No | Specifies the values to import. |
selection | string[] | Yes | Specifies the identifiers of the slots that should be imported. |
Return valueâ
Returns true
if the import succeeded or false
when there was an error and one or more of the specified fields could not be imported.
âī¸ Interfacesâ
đ IFieldByKey
â
Describes the interface to import data using the fields
function where the fields are referenced by their keys (unique identifiers).
Type declarationâ
interface IFieldByKey { key: string; value: any; reference?: string;Optional time?: number;Optional }
đˇī¸ key
â
Key of the field.
Typeâ
string
đˇī¸ reference
â
Contains the data reference.
Typeâ
string