Description
In Smenso, a button can be configured so that calculations are executed immediately when the button is clicked, and the result is written to a specific field. This feature allows for dynamically updating fields with calculation results, without requiring additional steps.
Important: SetField can only be used within the Process() function, which must be defined in a button (createButton). Otherwise, using SetField will cause an error.
Usage
The calculations are specified within the button’s action definition. Any calculations can be performed and then written to a target field using SetField("FieldName", value).
Syntax
createButton(state, title, tooltip, action, [borderColor], [fillColor], [textColor], [successMessage], [failureMessage], [icon])
Examples
| Description | Formula |
|---|---|
| Simple calculation and writing |
createButton(
1,
"Perform Calculation",
"Calculates total costs and writes them to a field",
"Process(
SetField('Total Costs', sumAll('Kosten', true))
)",
"",
"",
"",
"The calculation was carried out successfully.",
"Error during calculation.",
"calculator"
)
|
| Calculations with variables |
createButton(
1,
"Cost Calculation",
"Calculates net costs and writes them to a field",
"Process(
set('NetCosts', sumAll('Kosten', true) - flavor('Rabatt')),
SetField('NetCosts', get('NetCosts'))
)",
"",
"",
"",
"Net costs have been calculated.",
"Error during net cost calculation.",
"calculator"
)
|
| Conditional calculations with if |
createButton(
1,
"Conditional Calculation",
"Calculates net costs depending on the category and writes them to a field",
"Process(
set('CalculatedResult',
if(flavor('Kategorie') == 'Marketing',
sumAll('Kosten', true) * 0.9,
sumAll('Kosten', true)
)
),
SetField('NetCosts', get('CalculatedResult'))
)",
"",
"",
"",
"The calculation was carried out successfully.",
"Error during calculation.",
"settings"
)
|
Notes
- Combining
setandSetFieldis especially useful for storing and using intermediate results. - Important:
SetFieldmust be called insideProcess(); otherwise, it will not work. - Fields written with
SetFieldshould be correctly defined in advance to avoid errors. - Using the
iffunction enables complex conditional calculations and increases the flexibility of button actions.
Comments
0 comments
Please sign in to leave a comment.