DataLookup
Creates a Data Lookup definition (dl_definition) that automatically copies field
values from a matching record (the matcher) to a target record (the source)
when configurable match conditions are met.
Signature
DataLookup(config)
Usage
import { DataLookup } from '@servicenow/sdk/core'
DataLookup({
$id: Now.ID['priority-impact-lookup'],
name: 'Priority Impact Lookup',
sourceTable: 'task',
matcherTable: 'dl_u_priority',
matchRules: [
{ $id: Now.ID['priority-impact-match-priority'], sourceField: 'priority', matcherField: 'priority', exactMatch: true },
],
setRules: [
{ $id: Now.ID['priority-impact-set-impact'], targetField: 'impact', matcherField: 'impact', alwaysReplace: false },
],
})
Parameters
config
DataLookupConfig<S extends TableName, M extends TableName>
The Data Lookup configuration object.
Properties:
-
$id (required):
NowIdStable identifier for this lookup definition. Used to track the record across builds and prevent duplicates. -
name (required):
stringDisplay name of the lookup definition. Must be 40 characters or fewer. -
sourceTable (required):
SThe table whose records trigger the lookup and receive the copied field values. In a scoped app (non-global, non-sn_/now_), must be in the same scope as the data lookup definition (prefixed<scope>_). To target an OOB table such asincidentorproblem, use a global-scope app or a scoped table that extends the OOB table. Must be in the same scope as the data lookup definition — a build error is emitted if a cross-scope matcher table is detected. -
matcherTable (required):
MThe custom matcher table whose rows are searched to find a matching record. The table must extenddl_matcherand must be created separately usingTable()before the Data Lookup Definition is deployed. Must be in the same scope as the data lookup definition — a build error is emitted if a cross-scope matcher table is detected.x_(customer/partner apps),sn_, andnow_(ServiceNow-built apps) are all treated as scoped prefixes. -
active (optional, default:
true):booleanWhether this lookup definition is active and evaluated during record operations. -
runOnInsert (optional, default:
true):booleanWhether the lookup runs when a source record is inserted. -
runOnUpdate (optional, default:
false):booleanWhether the lookup runs when a source record is updated. Defaults tofalse— a common source of confusion when lookups appear not to fire on updates. -
runOnFormChange (optional, default:
true):booleanWhether the lookup runs on form change (client-side evaluation). -
protectionPolicy (optional):
'read' | 'protected'Controls edit access for other developers after the application is installed.'read': Others can view this record's configuration but cannot change it.'protected': Others cannot change this record.- Omit to allow other developers to customize this record.
-
matchRules (optional):
DataLookupMatchRule<S, M>[]Rules that define when the lookup applies. Each rule compares a field on the source record against a field on the matcher record. All match rules must pass for the lookup to trigger. When omitted, all records match.DataLookupMatchRuleproperties:-
$id (required):
NowIdStable identifier for this match rule. Each rule is stored as its owndl_definition_rel_matchrecord — provide a uniqueNow.ID['...']so the same sys_id is preserved across builds and developer machines. -
sourceField (required):
keyof FullSchema<S> | SystemColumns | (string & {})The field name on the source table to compare. -
matcherField (required):
keyof FullSchema<M> | SystemColumns | (string & {})The field name on the matcher table to compare against. -
exactMatch (optional, default:
false):booleanWhentrue, requires an exact value match. Whenfalse, allows partial or range matching depending on field type.
-
-
setRules (optional):
DataLookupSetRule<S, M>[]Rules that define which fields are copied from the matcher record to the source record when the lookup applies. When omitted, no fields are copied.DataLookupSetRuleproperties:-
$id (required):
NowIdStable identifier for this set rule. Each rule is stored as its owndl_definition_rel_setrecord — provide a uniqueNow.ID['...']so the same sys_id is preserved across builds and developer machines. -
targetField (required):
keyof FullSchema<S> | SystemColumns | (string & {})The field name on the source table to write the copied value into. -
matcherField (required):
keyof FullSchema<M> | SystemColumns | (string & {})The field name on the matcher table to read the value from. -
alwaysReplace (optional, default:
false):booleanWhentrue, the field value is always overwritten even if already set. Whenfalse, the field is only set if it is currently empty.
-
Validation Rules
-
Name length: The
nameproperty must be 40 characters or fewer. Names longer than 40 characters cause a build error. -
Source and matcher table scope: In a scoped app (non-global, non-
sn_/now_), bothsourceTableandmatcherTablemust be in the same scope as the data lookup definition. The build plugin emits an error diagnostic for either table that violates this constraint. To use OOB tables such asincidentorproblem, use a global-scope app or a scoped extension table. -
Matcher Table Seed Data — active Field Required: Ensure that the
activefield is set totruefor each record in the matcher table. This is because the Data Lookup engine queries the matcher table with an implicitactive=truefilter, and records whereactiveisnullorfalsewill never match.