A Practical Guide to Dynamic Logic and Context-Aware Data:
Reference events, records, users, and system data without creating new fields
Smart Variables allow you to dynamically reference information about the current record, event, user, or system context—without needing to create additional fields. They are especially powerful in longitudinal and repeating projects, and when building advanced logic.
Core Principle: Smart Variables allow you to reference context (e.g., current event, previous instance, record ID) dynamically within logic, calculations, and other REDCap features.
⚠️ Important: Smart Variables do not store data—they dynamically return values based on the current context.
On this page
What Smart Variables Do
- Reference the current record ID
- Pull values from other events
- Identify first/last events or instances
- Track user and timestamp information
- Enable dynamic logic without extra fields
✅ Best Practice: Use Smart Variables to reduce redundancy and avoid creating unnecessary fields.
Basic Syntax
Smart Variables are referenced using square brackets, just like regular fields:
[record-id] [current-event-name] [first-instance]
Tip: Smart Variables can be used anywhere logic is supported (branching, ASIs, Alerts, calculations).
Common Smart Variables
| Variable | Description |
|---|---|
[record-id] |
Current record ID |
[event-name] |
Current event |
[user-name] |
Current user |
Event-Based Smart Variables
[first-event-name] [last-event-name] [current-event-name]
Example:
[first-event-name][weight]
⚠️ Important: Event names must match exactly.
Repeating Instruments
[first-instance] [last-instance] [current-instance]
Example:
[blood_pressure][last-instance]
Tip: Useful for pulling latest values dynamically.
Record-Level Variables
[record-id] [redcap-event-name]
User & System Variables
[username] [user-email] [today] [now]
⚠️ Important: Values update dynamically each time accessed.
Real-World Examples
Use Latest Value
[weight][last-instance]
Reference Baseline
[first-event-name][age]
Timestamp
[now]
Common Mistakes
- ❌ Treating Smart Variables like stored data
- ❌ Incorrect event names
- ❌ Using without testing context
Best Practices
- Use for dynamic references
- Test in real records
- Keep logic readable