Fields
Fields define the data structure of objects. The SDK provides methods to query field metadata including types, choices, and reference targets.
get_fields()
Query fields in three ways. Optional keyword-only filters apply only when you pass an object (object_id); they map to the REST query parameters editable and entryForm.
from dealcloud_sdk import DealCloud, DealCloudConfig
config = DealCloudConfig(
siteUrl="yoursite.dealcloud.com",
clientId=12345,
clientSecret="your-secret",
)
dc = DealCloud.from_config_object(config)
# All fields in the site
all_fields = dc.get_fields()
print(f"Total fields: {len(all_fields)}")Parameters
| Parameter | Type | Description |
|---|---|---|
object_id | int | str | None | Entry type ID or API name. Omit with field_id or neither for all fields. |
field_id | int | None | Single field ID (mutually exclusive with object_id). |
editable | bool | None | Keyword-only. When set with object_id, filters editable vs non-editable fields (editable query param). |
entry_form | bool | None | Keyword-only. When set with object_id, filters fields shown or not shown on the entry form (entryForm query param). |
You cannot combine object_id and field_id, or use editable / entry_form with field_id alone. If either editable or entry_form is set, object_id is required.
Calls that include editable or entry_form do not use the SDK fields cache (each request hits the API). Unfiltered get_fields(object_id=...) remains cached per object until you call clear_fields_cache() or clear_schema_cache().
Optional filters (entry type fields)
Use editable and/or entry_form when you need the same subsets the Schema API exposes for GET .../schema/entrytypes/{entryTypeId}/fields:
# Editable fields only
editable_only = dc.get_fields(object_id="Company", editable=True)
# Fields present on the entry form
on_form = dc.get_fields(object_id="Company", entry_form=True)
# Combine filters (both query params)
editable_on_form = dc.get_fields(
object_id="Company",
editable=True,
entry_form=True,
)
# Non-editable fields (API: editable=false)
read_only = dc.get_fields(object_id="Company", editable=False)Field Properties
| Property | Type | Description |
|---|---|---|
id | int | Unique field ID |
name | str | Display name |
apiName | str | API name (for code) |
fieldType | int | Field type ID |
isRequired | bool | Is required field |
isMultiSelect | bool | Allows multiple values |
isCalculated | bool | Is calculated field |
isAttachment | bool | Is attachment reference |
description | str | Field description |
formula | str | Formula (if calculated) |
choiceValues | List[ChoiceValue] | Choice options |
entryLists | List[int] | Reference target object IDs |
systemFieldType | int | System field type (if system) |
Field Types
Common field types:
| Type ID | Name | Description |
|---|---|---|
| 1 | Text | Single-line text |
| 2 | Number | Numeric values |
| 3 | Date | Date values |
| 4 | DateTime | Date and time |
| 5 | Choice/Reference | Choice list or reference |
| 6 | Boolean | True/false |
| 7 | Memo | Multi-line text |
| 13 | Binary | File/document |
| 16 | Image | Image field |
# Get field type name
from dealcloud_sdk.constants import get_field_type_name
field = dc.get_fields("Company")[0]
type_name = get_field_type_name(field.fieldType)
print(f"{field.apiName}: {type_name}")get_fields_by_ids()
Fetch multiple fields by ID in a single request:
field_ids = [12345, 12346, 12347]
fields = dc.get_fields_by_ids(field_ids)
for field in fields:
print(f"{field.id}: {field.apiName}")Choice Fields
Choice fields have choiceValues:
# Get a choice field
fields = dc.get_fields("Company")
industry = next(f for f in fields if f.apiName == "Industry")
# List choice values
if industry.choiceValues:
for choice in industry.choiceValues:
print(f"{choice.id}: {choice.name}")Choice Value Properties
| Property | Type | Description |
|---|---|---|
id | int | Choice value ID |
name | str | Display name |
parentId | int | Parent choice (hierarchical) |
seqNumber | int | Sort order |
Building Choice Maps
def get_choice_map(field):
"""Build name → ID mapping for a choice field."""
if not field.choiceValues:
return {}
return {c.name: c.id for c in field.choiceValues}
fields = dc.get_fields("Company")
industry = next(f for f in fields if f.apiName == "Industry")
choice_map = get_choice_map(industry)
# {"Technology": 101, "Finance": 102, "Healthcare": 103, ...}
# Use in data operations
tech_id = choice_map.get("Technology")Appending Choice Values
Use append_choice_values() to add new options to an existing choice field without removing existing choices:
# Add new choices by field ID
dc.append_choice_values(
field_id=12345,
choice_values=[
{"name": "New Option A"},
{"name": "New Option B"},
]
)
# Add new choices by field API name
dc.append_choice_values(
field_id="IndustryType",
choice_values=[{"name": "Fintech"}, {"name": "Biotech"}]
)This appends to the existing choices — it will not remove or modify any existing choice values.
Parameters
| Parameter | Type | Description |
|---|---|---|
field_id | int | str | Field ID or API name of the choice field |
choice_values | List[dict] | Choice values to append (each with a "name" key) |
Example: Sync Choices from External System
def sync_choices(dc, field_id, external_values: list[str]):
"""Add any new choices that don't already exist."""
fields = dc.get_fields(field_id=field_id)
field = fields[0]
existing = {c.name for c in (field.choiceValues or [])}
new_values = [{"name": v} for v in external_values if v not in existing]
if new_values:
dc.append_choice_values(field_id=field_id, choice_values=new_values)
print(f"Added {len(new_values)} new choices")
else:
print("All choices already exist")
sync_choices(dc, 12345, ["Technology", "Finance", "New Sector"])Reference Fields
Reference fields point to other objects via entryLists:
# Find reference fields
fields = dc.get_fields("Contact")
ref_fields = [f for f in fields if f.entryLists]
for field in ref_fields:
targets = field.entryLists # List of target object IDs
print(f"{field.apiName} → Object IDs: {targets}")Reference Target Lookup
def get_reference_targets(dc, field):
"""Get object names that a reference field points to."""
if not field.entryLists:
return []
objects = dc.get_objects()
obj_map = {o.id: o.apiName for o in objects}
return [obj_map.get(oid, f"Unknown({oid})") for oid in field.entryLists]
fields = dc.get_fields("Contact")
company_field = next(f for f in fields if f.apiName == "Company")
targets = get_reference_targets(dc, company_field)
print(f"Company field targets: {targets}") # ["Company"]System Fields
System fields are automatically created by DealCloud:
# Filter system fields
fields = dc.get_fields("Company")
system_fields = [f for f in fields if f.systemFieldType is not None]
custom_fields = [f for f in fields if f.systemFieldType is None]
print(f"System: {len(system_fields)}, Custom: {len(custom_fields)}")Common system fields:
| API Name | Description |
|---|---|
EntryId | Unique record ID |
CreatedDate | Record creation date |
ModifiedDate | Last modified date |
CreatedBy | User who created |
ModifiedBy | User who modified |
Field Lookup Helpers
By API Name
def get_field_by_api_name(dc, object_id: str, api_name: str):
"""Get field by its API name."""
fields = dc.get_fields(object_id)
return next((f for f in fields if f.apiName == api_name), None)
industry = get_field_by_api_name(dc, "Company", "Industry")By Display Name
def get_field_by_name(dc, object_id: str, display_name: str):
"""Get field by its display name."""
fields = dc.get_fields(object_id)
return next((f for f in fields if f.name == display_name), None)
industry = get_field_by_name(dc, "Company", "Industry Type")Field Map
def get_field_map(dc, object_id: str):
"""Build API name → Field mapping."""
fields = dc.get_fields(object_id)
return {f.apiName: f for f in fields}
company_fields = get_field_map(dc, "Company")
industry = company_fields.get("Industry")Common Patterns
Export Field Documentation
import pandas as pd
def export_field_docs(dc, object_id: str, filepath: str):
"""Export field documentation to Excel."""
fields = dc.get_fields(object_id)
records = []
for f in fields:
records.append({
"Field ID": f.id,
"API Name": f.apiName,
"Display Name": f.name,
"Type ID": f.fieldType,
"Required": f.isRequired,
"Multi-Select": f.isMultiSelect,
"Calculated": f.isCalculated,
"Description": f.description or "",
"Choices": len(f.choiceValues) if f.choiceValues else 0,
"References": ", ".join(map(str, f.entryLists or []))
})
df = pd.DataFrame(records)
df.to_excel(filepath, index=False)
export_field_docs(dc, "Company", "company_fields.xlsx")Validate Data Against Schema
def validate_record(dc, object_id: str, record: dict):
"""Validate a record against field schema."""
fields = dc.get_fields(object_id)
field_map = {f.apiName: f for f in fields}
errors = []
# Check required fields
for field in fields:
if field.isRequired and field.apiName not in record:
errors.append(f"Missing required field: {field.apiName}")
# Check field names
for key in record:
if key not in field_map and key != "EntryId":
errors.append(f"Unknown field: {key}")
return errors
errors = validate_record(dc, "Company", {"CompanyName": "Test"})
if errors:
print("Validation errors:", errors)Related
- Objects - Object metadata
- Metadata Types - Field type reference
- Schema Export - Export to Excel