defineField() to add a field to an object you don’t own — a standard Twenty object like Person or Company, or an object shipped by another installed app. Unlike inline fields declared inside defineObject, standalone fields require an objectUniversalIdentifier to specify which object they extend.
src/fields/company-loyalty-tier.field.ts
Key points
-
objectUniversalIdentifieridentifies the target object. For standard Twenty objects, import the constant fromtwenty-sdk: -
When defining fields inline inside
defineObject(), you do not needobjectUniversalIdentifier— it’s inherited from the parent object. -
defineField()is the only way to add fields to objects you didn’t create withdefineObject(). -
SELECTandMULTI_SELECTfollow the same option validation and color rules as inline fields. An omitted or null color defaults togray; unsupported colors are rejected. -
File location is up to you. The convention is
src/fields/<name>.field.ts, but the SDK detects fields anywhere insrc/. -
writabilitycan also be set per field:MetadataWritability.APPLICATIONrestricts writes to your app’s own logic functions,MetadataWritability.SYSTEMis reserved for platform-managed data. A field’s writability can only be stricter than its object’s level, and reads are unaffected. See Objects for the full semantics. -
isSearchable: truecan be set ondefineField()with the same constraints as inline fields (searchable target object, text-compatible field type), so records of the target object become findable through your field’s values in full-text search. -
isAuditLogged: falsecan be set ondefineField()to keep the field’s changes out of the target record’s timeline, which matters most for fields your app rewrites on a schedule. -
To add a tab to a standard page layout (e.g. the Task or Company detail page), use
definePageLayoutTabwithSTANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERSfromtwenty-sdk/define.
Adding a relation to an existing object
To add a relation field (e.g. linking your custom object to a standardPerson), use defineField() with FieldType.RELATION. The pattern is the same as for inline relations but with objectUniversalIdentifier set explicitly. See Relations for the bidirectional pattern.