add_field
Adds a new field to an existing REDCap instrument, updating the data dictionary with support for field types, validation, and branching logic.
Instructions
Add a new field to an existing instrument.
Exports the current data dictionary, inserts the new field, and imports the updated dictionary back. The operation is atomic from REDCap's perspective.
Args: form_name: Internal name of the instrument to add the field to. field_name: Variable name for the new field (lowercase, underscores, no spaces). field_type: One of: text, notes, calc, radio, checkbox, yesno, truefalse, select, slider, file, descriptive. field_label: Display label shown to data-entry users. choices: Choice definitions for radio/checkbox/select fields, formatted as "1, Label 1 | 2, Label 2". Ignored for other types. required: Whether the field must be filled before saving the record. branching_logic: Show/hide logic expression (e.g. "[age] > 18"). field_note: Helper text displayed below the field. section_header: Section header to display above this field. validation: Validation type for text fields (e.g. integer, number, date_ymd, email, phone). validation_min: Minimum allowed value (for validated text fields). validation_max: Maximum allowed value (for validated text fields). field_annotation: REDCap action tags and annotations (e.g. @HIDDEN). after_field: Insert the new field immediately after this field name. If None, the field is appended at the end of the instrument.
Returns: Confirmation message with the count of updated fields.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| choices | No | ||
| required | No | ||
| form_name | Yes | ||
| field_name | Yes | ||
| field_note | No | ||
| field_type | Yes | ||
| validation | No | ||
| after_field | No | ||
| field_label | Yes | ||
| section_header | No | ||
| validation_max | No | ||
| validation_min | No | ||
| branching_logic | No | ||
| field_annotation | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |