Set field values with formulas
Use a formula in a Set Field workflow step to calculate a field’s value from other fields when the step runs, such as a review end date 90 days after the review start date.
Prerequisites
Add a formula to a Set Field step
Open the workflow in the workflow editor and double-click the Set Field step.4
Under Target Field, select the custom field to set.
Under Action, select Formula.
Under Fields the Formula Reads, select each field of the record or artifact that your formula uses.
On an artifact workflow, the formula can also read fields on the artifact’s parent record. Under Parent Record Fields, click a field to copy the code that reads it, such as
params.model.get("review_start_date"), then paste it into your formula. The formula reads the parent record but never changes it.Replace the starter formula in the code box with your own.5
Select the Result Type for the value your formula returns. Only the result types that fit the target field are offered.
Leave Must produce a value selected to treat an empty result as a failure. Clear it to leave the field unchanged when the formula returns no value.
(Optional) Under Test with a Record, or Test with an Artifact on an artifact workflow, select a record or artifact and click Run Test.
The test shows the result, whether it fits the target field, and the inputs the formula received. Testing never changes the record or artifact.
(Optional) Under If a Formula Fails, Notify, select the roles to notify when a formula in this step fails.
If you select no roles, or nobody holds the selected roles on the record, organization admins are notified instead.
Click Update Step to apply your changes.
5 Refer to the Calculation field type for the formula syntax, the params dictionary, and the available helpers:
6 Saving is also blocked if a formula has no return that produces a value, builds field keys while it runs, or reads fields that are not available in a workflow step.
When you save the workflow, ValidMind checks each formula. Saving is blocked if a formula has a syntax error or reads a field you did not add under Fields the Formula Reads.6
Fields that accept a formula
The Formula action is available for custom fields of these types. Core fields cannot be set with a formula.
| Result Type | Field types it can set |
|---|---|
| Date | Date, Date Time |
| Number | Number |
| Boolean | Checkbox |
| Text | Single Line Text, Long Text, Email, URL, Single Select |
A result must also fit the field’s own settings. For example, a Single Select field only accepts one of its options, and a Date Time field needs a result that includes a time, such as today() + "T09:00:00Z".
Write formulas for a Set Field step
Set Field formulas use the same Starlark syntax and helper functions as calculated fields.7 A few differences apply in a workflow step:
7 Refer to the Calculation field type for the formula syntax, the params dictionary, and the available helpers:
- Each field the formula reads must be added under Fields the Formula Reads. Read it with a fixed key, such as
params.get("review_start_date"). - Parent record fields, read with
params.model, are available on artifact workflows only. - On artifact workflows,
params["model_stage"]andparams["stakeholders"]are not available. params["integrations"]is not available.- A formula can be up to 10,000 characters long.
Set several fields in one step
A Set Field step works through its fields from top to bottom, and a formula can read the value that a field above it sets in the same step.
- Use the move up and move down buttons on each field to change the order.
- If a formula reads a field that is set further down in the step, a warning tells you that the formula gets the value the record has now. Move that field above the formula to use the new value.
- Values from Generate with AI are generated after the step’s other fields are set. A formula that reads a field set by AI in the same step gets the value the record has now.
When a step has more than one field and at least one formula, use Test the Step with a Record, or Test the Step with an Artifact, to preview what each field would be set to in order. A field that fails shows its cause, and the formulas that read it show as not evaluated. Testing never changes the record or artifact.
What happens when the step runs
The formula is calculated once, when the workflow reaches the step. The value is not recalculated later when the fields it reads change. To keep a value up to date at all times, use a calculated field instead.8
8 Refer to the Calculation field type for the formula syntax, the params dictionary, and the available helpers:
The step sets all of its fields or none of them. Before anything is written, each value is checked against its field. If every value fits, all of them are written:
- The record’s activity log shows each field that changed, the step that changed it, and the formula that produced the value.
- The step’s run history shows each field with its formula, the inputs the formula received, and its result.9
When a formula fails
A formula fails when it returns no value and Must produce a value is selected, or when it returns a value the field cannot store. When a formula fails:
- Nothing in the step is written, including the step’s other fields.
- The workflow continues to its next step.
- The record’s activity log records which field could not be set and why. On an artifact workflow, this entry goes on the artifact’s parent record.
- Each user who holds a role under If a Formula Fails, Notify gets a task in My Inbox. If no roles are selected, or nobody holds them on the record, organization admins get the task.
The task names the record, the workflow, the step, and the field that failed, and lists the fields that were not set because of it. Fix the record data, then set those fields by hand or run the workflow again.
- If the step fails again on the same record while the task is open, the task is updated with the number of failures.
- Mark as Done closes the task for everyone who received it.
- The task also closes on its own the next time the step runs on that record without failing.
A Set Field step that sets only fixed values works the same way: if one value does not fit its field, nothing in the step is written and organization admins get the task. Steps that use Generate with AI and no formula do not follow this rule.
Changes to fields and roles used by formulas
- When you rename a custom field key, the formulas that read the field are updated to use the new key.10
- You cannot delete a field that a formula in an active workflow reads, or a role selected under If a Formula Fails, Notify. Remove it from the workflow first.