Custom Fields
Custom fields allow you to add custom data to any entity in Erplain. They use a morph relation pattern, allowing values to be attached to any supported entity type.
Available fields
CustomField
| Field | Type | Description |
|---|---|---|
id | Int | Unique identifier. |
label | String | Display label. |
identifier | String | Machine-readable identifier. |
input_type | CustomFieldInputType | Input widget type. |
model_type | CustomFieldModelType | Target entity type. |
metadata | JSON | Additional metadata (e.g., select options). |
weight | Int | Sort order. |
values | [CustomFieldValue] | All values for this field. |
CustomFieldValue
| Field | Type | Description |
|---|---|---|
id | Int | Unique identifier. |
custom_field_id | Int | FK to CustomField. |
custom_field | CustomField | Associated field definition. |
custom_field_valuable_id | Int | Morph ID (entity instance). |
custom_field_valuable_type | String | Morph type (e.g., "Product"). |
text_value | String | Value for Text, Selectlist, Radios, Checkboxes. |
textarea_value | String | Value for Textarea. |
number_value | Float | Value for Number. |
boolean_value | Boolean | Value for Boolean. |
date_value | Date | Value for Date. |
datetime_value | DateTime | Value for Datetime. |
value | Mixed | Virtual accessor - returns the correct typed value. |
EntityCustomField
| Field | Type | Description |
|---|---|---|
custom_field_id | ID | FK to CustomField. |
custom_field | CustomField | Field definition. |
values | [CustomFieldValue] | Values for this field. |
Enums
CustomFieldInputType
| Value | DB Column | Description |
|---|---|---|
Text | text_value | Single-line text. |
Textarea | textarea_value | Multi-line text. |
Number | number_value | Numeric value. |
Boolean | boolean_value | True/false. |
Date | date_value | Date only (Y-m-d). |
Datetime | datetime_value | Date + time. |
Selectlist | text_value | Dropdown (options in metadata). |
Radios | text_value | Radio buttons. |
Checkboxes | text_value | Multiple checkboxes. |
CustomFieldModelType
| Value | Entity |
|---|---|
Customer | Contact (Customer) |
Supplier | Contact (Supplier) |
Employee | Employee/User |
Product | Product |
Variant | Product Variant |
Estimate | Estimate |
Order | Sales Order |
ShippingOrder | Shipping Order |
Invoice | Invoice |
Subscription | Subscription |
ProductReturn | Product Return |
Refund | Refund |
CreditNote | Credit Note |
Purchase | Purchase Order |
PurchaseReceipt | Purchase Receipt |
StockEntry | Stock Entry |
StockRemoval | Stock Removal |
StockTransfer | Stock Transfer |
Payment | Payment |
CustomField
Returns a single custom field by id.
query GetCustomField($id: ID!) {
CustomField(id: $id) {
id
label
identifier
input_type
model_type
metadata
weight
values {
id
custom_field_valuable_id
custom_field_valuable_type
text_value
number_value
boolean_value
}
}
}CustomFields
Returns a paginated list of custom fields with sorting and filters.
query CustomFields(
$orderBy: [QueryCustomFieldsOrderByOrderByClause!]
$where: QueryCustomFieldsWhereWhereConditions
$search: String
) {
CustomFields(orderBy: $orderBy, where: $where, search: $search) {
id
label
identifier
input_type
model_type
weight
}
}Filters
The following fields can be used in the where parameter:
id, label, identifier, model_type, input_type.
Sorting
You can sort results using the orderBy parameter:
idlabelidentifierinput_typemodel_typeweight
Using Custom Fields on Entities
Custom fields are accessible on any supported entity via the custom_fields field:
query GetProduct($id: ID!) {
Product(id: $id) {
id
label
custom_fields {
custom_field_id
custom_field {
label
identifier
input_type
}
values {
text_value
number_value
boolean_value
date_value
}
}
}
}Supported Entities
| Entity | Query |
|---|---|
| Customer | Customer(id: $id) { custom_fields { ... } } |
| Supplier | Supplier(id: $id) { custom_fields { ... } } |
| Employee | Employee(id: $id) { custom_fields { ... } } |
| Product | Product(id: $id) { custom_fields { ... } } |
| Variant | Variant(id: $id) { custom_fields { ... } } |
| Order | Order(id: $id) { custom_fields { ... } } |
| Estimate | Estimate(id: $id) { custom_fields { ... } } |
| Invoice | Invoice(id: $id) { custom_fields { ... } } |
| ShippingOrder | ShippingOrder(id: $id) { custom_fields { ... } } |
| Purchase | Purchase(id: $id) { custom_fields { ... } } |
| PurchaseReceipt | PurchaseReceipt(id: $id) { custom_fields { ... } } |
| ProductReturn | ProductReturn(id: $id) { custom_fields { ... } } |
| Refund | Refund(id: $id) { custom_fields { ... } } |
| CreditNote | CreditNote(id: $id) { custom_fields { ... } } |
| StockAdjustment | StockAdjustment(id: $id) { custom_fields { ... } } |
| Payment | Payment(id: $id) { custom_fields { ... } } |
| Subscription | Subscription(id: $id) { custom_fields { ... } } |
Special case - Product: Products have an additional variant_custom_fields field that returns custom fields from the first variant.
