Skip to main content
Version: 4.1 (2026-H2)

CodeDataProvider


The CodeDataProvider supplies the data of an Object or ObjectCollection from a JavaScript snippet, instead of loading it from an external source (CSV, Excel, SQL, HTTP). It is useful for providing entries that are computed, derived from the entered search parameters, or taken from the Connect data context.

The CodeDataProvider uses the same mechanism as the other DataProviders and is available both in the primedocs desktop client and in primedocs Web.

Configuration

<ObjectCollection Id="Positions" Label="Line items">
<Schema>
<Text Id="Article" Label="Article" />
<Text Id="Amount" Label="Amount" />
</Schema>
<DataProviders>
<CodeDataProvider DisplayName="From Connect data">
<SearchParameters>
<Text Id="Category" Label="Category" field-Value="Data.Category" />
</SearchParameters>
<Code>
function main() {
var category = $("Category");
return [
{ Article: "Example " + category, Amount: "100.00" }
];
}
</Code>
</CodeDataProvider>
</DataProviders>
</ObjectCollection>
note

Unlike the file-based or HTTP providers, the CodeDataProvider needs no Mapping: the properties of the objects returned by the snippet are matched to the Schema fields by name. Nested objects are flattened with dot notation (e.g. Address.City).

Attributes

AttributeDescription
DisplayName / translate-DisplayName (optional)Display name of the provider in the UI.
ReadOnly (optional)When true, the fields loaded via this provider are read-only.
AutoAddAllEntries (optional)When true, all entries returned by the snippet are added to the collection automatically.

Elements

ElementDescription
Code (required)JavaScript with a main() function that returns an array of objects. Each object is an entry; its properties become fields.
SearchParameters (optional)Search mask with Text, Date, YesNo, Choice (as in Forms). Use field-Value (value from the Connect data context) or parent-Value (field of the parent object) to pre-populate parameters.

JavaScript API

The $ object is available inside the Code snippet:

CallDescription
$.parameter("Id") or $("Id")Value of a configured search parameter.
$("Data.Key")Value from the Connect data context.
$.parent("FieldId")Value of a field of the parent object (in nested Object/ObjectCollection structures).
note

The CodeDataProvider does not participate in the Loading path of the ProviderPipeline, as it has no flat search step that could be re-mapped on load.