Custom Fields
albert.collections.custom_fields.CustomFieldCollection
Bases: BaseCollection
Manage Custom Fields in the Albert platform.
A Custom Field defines an allowed metadata field on an Albert entity. The
metadata dicts on entities such as Projects, Inventory Items, Users, Tasks,
and Lots may only use fields that have been defined here; a Custom Field is
the schema that gives a metadata key its name, type, and validation rules.
The field's FieldType determines the
shape of the stored value (e.g. string, number, list). When the
type is list, the FieldCategory
determines who may add new allowed items to that list:
FieldCategory.USER_DEFINED: general users can add items.FieldCategory.BUSINESS_DEFINED: only admins can add items.
Creating a list custom field establishes a new list (identified by a
list_type, typically the field's name) for options to be added to. Those
options are ListItem records managed through
ListsCollection (client.lists); add
each option with its list_type set to this field.
Custom Field IDs use the CTF prefix. This is configuration/schema-level
data.
This collection is accessed as client.custom_fields.
Example
from albert import Albert
from albert.resources.custom_fields import (
CustomField,
FieldCategory,
FieldType,
ServiceType,
)
client = Albert()
# A business-defined single-select list field on Projects
stage_gate_field = CustomField(
name="stage_gate_status",
display_name="Stage Gate",
field_type=FieldType.LIST,
service=ServiceType.PROJECTS,
min=1,
max=1,
category=FieldCategory.BUSINESS_DEFINED,
)
# A free-text field on Projects
justification_field = CustomField(
name="justification",
display_name="Project Justification",
field_type=FieldType.STRING,
service=ServiceType.PROJECTS,
)
client.custom_fields.create(custom_field=stage_gate_field)
client.custom_fields.create(custom_field=justification_field)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for custom field requests. |
Methods:
| Name | Description |
|---|---|
create |
Create a new custom field. |
get_by_id |
Get a single custom field by its ID. |
get_by_name |
Get a custom field by its name. |
get_all |
Iterate over custom fields matching optional filters. |
get_searchable_fields |
Return the searchable custom fields configured for an entity/service. |
update |
Update an existing custom field. |
delete |
Delete a custom field by its ID. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/custom_fields.py
get_by_id
get_by_id(*, id: CustomFieldId) -> CustomField
Get a single custom field by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
CustomFieldId
|
The Custom Field ID (format |
required |
Returns:
| Type | Description |
|---|---|
CustomField
|
The fully populated custom field. |
Source code in src/albert/collections/custom_fields.py
get_by_name
get_by_name(
*, name: str, service: ServiceType | None = None
) -> CustomField | None
Get a custom field by its name.
Matching is case-insensitive. Pass service to disambiguate when the
same field name is used across different services.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the custom field (the |
required |
service
|
ServiceType
|
The service the field relates to. Defaults to all services. |
None
|
Returns:
| Type | Description |
|---|---|
CustomField or None
|
The matching custom field, or None if not found. |
Source code in src/albert/collections/custom_fields.py
get_all
get_all(
*,
name: str | None = None,
type: FieldType | None = None,
service: ServiceType | None = None,
lookup_column: bool | None = None,
lookup_row: bool | None = None,
entity_category: EntityCategory | None = None,
custom_entity_category: str | None = None,
start_key: str | None = None,
max_items: int | None = None,
) -> Iterator[CustomField]
Iterate over custom fields matching the given filters.
Results are returned as a lazily paginated iterator, so iterating fetches additional pages on demand.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Filter by field name. |
None
|
type
|
FieldType
|
Filter by field type (e.g. |
None
|
service
|
ServiceType
|
Filter by the service the field belongs to. If none, none will be returned. So, for best expected results, pass a service. |
None
|
lookup_column
|
bool
|
Filter to fields that are (or are not) lookup columns. |
None
|
lookup_row
|
bool
|
Filter to fields that are (or are not) lookup rows. |
None
|
entity_category
|
EntityCategory
|
Filter by supported entity category for the field. |
None
|
custom_entity_category
|
str
|
Filter by custom entity category configured for the field. |
None
|
start_key
|
str
|
Provide the |
None
|
max_items
|
int
|
Maximum number of items to return in total. If None, iterates over all matches. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[CustomField]
|
A lazily paginated iterator of matching custom fields. |
Source code in src/albert/collections/custom_fields.py
get_searchable_fields
get_searchable_fields(
*, entity: ServiceType
) -> dict[str, SearchableCustomField]
Return the custom fields configured as searchable for an entity.
Only string and list fields can be made searchable. Use this to
discover which metadata paths on an entity can be queried in search.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
ServiceType
|
The entity/service to fetch searchable fields for. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, SearchableCustomField]
|
Mapping of metadata paths to their searchable field descriptors. |
Source code in src/albert/collections/custom_fields.py
create
create(*, custom_field: CustomField) -> CustomField
Create a new custom field.
Example
from albert import Albert
from albert.resources.custom_fields import (
CustomField,
FieldType,
ServiceType,
)
client = Albert()
field = CustomField(
name="justification",
display_name="Project Justification",
field_type=FieldType.STRING,
service=ServiceType.PROJECTS,
)
created = client.custom_fields.create(custom_field=field)
created.id
# 'CTF1'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_field
|
CustomField
|
The custom field to create. |
required |
Returns:
| Type | Description |
|---|---|
CustomField
|
The newly created custom field, populated with its assigned Custom Field ID. |
Source code in src/albert/collections/custom_fields.py
update
update(*, custom_field: CustomField) -> CustomField
Update an existing custom field.
Fetch the field (e.g. with get_by_id), modify the updatable fields
on the returned object, then pass it here. Only the fields listed in Notes
are applied; changes to other fields are ignored.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_field
|
CustomField
|
The custom field to update. Its |
required |
Returns:
| Type | Description |
|---|---|
CustomField
|
The updated custom field as registered in Albert. |
Notes
The following fields can be updated: custom_entity_categories,
default, display_name, editable, entity_categories,
hidden, lookup_column, lookup_row, max, min,
multiselect, pattern, required, searchable,
ui_components.
Source code in src/albert/collections/custom_fields.py
delete
delete(*, id: CustomFieldId) -> None
Delete a custom field by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
CustomFieldId
|
The Custom Field ID to delete (format |
required |
Returns:
| Type | Description |
|---|---|
None
|
|