Rules: data import (IMPORT)
Import rules (IMPORT)
-
Before working with
IMPORT, the assistant MUST identify elements in this order:- module and namespace that own the import flow
- target classes that will be created or updated
- staging properties used during import
- import actions
- import forms, if the payload is hierarchical
-
The assistant MUST choose the import style intentionally:
- flat files (
CSV,XLS,DBF,TABLE) -> preferIMPORT ... TOorFIELDS - nested
JSON/XML, parent-child structures, namespaces, orEXTIDmapping -> prefer form import - row-at-a-time integration responses
-> prefer
FIELDS ... DO
- flat files (
-
For flat imports that need validation, deduplication, multi-pass processing, or post-processing, the assistant SHOULD stage data into
LOCALproperties first, usually byINTEGERrow, then process it in a separateFOR imported(INTEGER i)pass. -
The assistant SHOULD use
FIELDS ... DOwhen imported values are consumed only once and introducing reusable local properties would add noise. -
The assistant SHOULD specify column mappings explicitly when the external template is fixed or sparse.
Sequential mapping without explicit column IDs is acceptable only when column order itself is the agreed interface.
-
For form import, the assistant MUST declare a dedicated import form before use.
The form MUST use one object per object group with numeric or concrete user classes.
The form SHOULD mirror the external structure with:
FILTERSfor parent-child linksEXTID,FORMEXTID, groups, andATTRonly where the external schema requires them
The assistant MUST remember that importing into a form cancels pending changes to imported form properties in the current session.
-
The assistant MUST choose format options explicitly when the external contract depends on them:
HEADER/NOHEADERSHEETCHARSET
The assistant SHOULD prefer
HEADERfor stableCSV/XLStemplates, becauseNOHEADERcan silently map missing or mistyped columns toNULL. -
The assistant MUST validate referenced business keys before creating or updating persistent objects.
Typical keys in this project are
id,number, partner or item codes, and external references.Each reference MUST be checked in a separate
FORusingGROUP SUM 1 BYover the imported key values.If possible, the assistant SHOULD NOT write resolved references to a separate
LOCALbefore the main import logic.Missing master data or malformed payloads MUST stop the import or surface a clear error.
-
The assistant SHOULD separate raw import from domain resolution:
- first parse the file or payload into locals or an import form
- then check references such as item, partner, status, type, or other lookups
- only then create or update domain objects
-
For user-started batch imports and external integrations, the assistant SHOULD isolate persistence in
NEWSESSION, and SHOULDAPPLY;after the domain writes of one import.Three of the change-session rules bite on every import, so they are stated here rather than left to a second lookup:
- a buffer filled in the upper session reaches the new one
only through
NESTED, on the operator or on theDATA LOCAL NESTEDdeclaration itself, and does not reach it at all underNEWSQL, which migrates nothing; - after
APPLY;the assistant MUST checkcanceled()before treating the import as done; - a failure raised by
APPLYitself is already shown to an interactive user, so an interactive import MUST NOT report it twice; an API or background import MUST surface it itself, throughapplyMessage()or an exception.
The rest of them are in the change-session article:
lsfusion_retrieve_docs(type='rules', query='change sessions'). - a buffer filled in the upper session reaches the new one
only through
-
The assistant MUST NOT partially persist a failed import silently. For failures the assistant detects on its own (missing references, malformed payload, pre-
APPLYvalidation), it SHOULD useMESSAGE,RETURN,throwException, or an explicit failure flag, consistent with the caller:- interactive import ->
MESSAGE - API or background integration -> exception or explicit failure state
- interactive import ->
-
For create-or-update synchronization imports, the assistant MUST separate object creation from property updates.
The assistant MUST make one separate pass that only creates the missing objects. A
FORis one way to write it; the bulkNEW ... WHERE ... TOform creates an object per matching set in a single operation and is the better one wherever it fits.If imported key values may be non-unique, the creation pass SHOULD iterate by grouped keys using
GROUP SUM ... BYrather than by raw imported rows.The assistant MUST then update the properties of the matched objects in a second separate pass — a direct
<- ... WHEREchanges every matching set at once, and aFORis needed only where the body does something a set-based change cannot.The assistant MUST NOT mix object creation and property updates in the same pass for synchronization imports.
If full synchronization is required, the assistant SHOULD add an explicit delete step.
-
If
LOCALstaging properties are used only in one import action, the assistant MUST declare them inside that action.The assistant SHOULD NOT lift such
LOCALproperties to module scope without need.Exception: a
LOCALproperty may be declared outside the action only when it must be used by an import form or reused by several related actions.