Description
The SetField function is used to programmatically set the value of a specific field within a project or a task. Typical use cases are buttons (createButton) or workflows that update fields automatically.
SetField is particularly helpful when data should be inserted into or updated in a custom field automatically.
Syntax
SetField(id: guid, fieldName: string, value: string)
Arguments
| Argument | Description |
|---|---|
id |
GUID of the target object (project/task) to write to. |
fieldName |
Name of the field whose value should be set. This can be a system field or a flavor. |
value |
Value to be written to the field. Always pass as a string. If another data type is required (e.g., number, date), you can use asType("string", ...). |
Return types
No return value. The function writes the specified value to the field.
Examples
| Description | Formula |
|---|---|
| Simple field update |
Process(
SetField("01234567-89ab-cdef-0123-456789abcdef", "Status", "In Progress")
)
Sets the value of the |
| Dynamic value (calculation as string) |
Process(
SetField("01234567-89ab-cdef-0123-456789abcdef", "Budget", asType("string", sumAll("Costs", true)))
)
Writes the sum of all costs as a string to the |
| Combination with a button |
createButton(
1,
"Status to 'Completed'",
"Click sets the status",
"Process(
SetField('01234567-89ab-cdef-0123-456789abcdef', 'Status', 'Completed')
)",
"",
"",
"",
"The status was successfully set to 'Completed'.",
"",
"check-circle"
)
A button that sets the status to “Completed” when clicked. |
Notes
- Exact name:
fieldNamemust exactly match the field name defined in Smenso. - Strings: All values must be passed as a
string. If needed, convert withasType("string", ...). - Use within
Process(): Always use withinProcess(), otherwise the error “Can not execute async functions outside async context” will appear.
Comments
0 comments
Please sign in to leave a comment.