Skip to content

Merge main into staging #455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added site/guide/model-inventory/calculation-field.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 27 additions & 1 deletion site/guide/model-inventory/manage-model-inventory-fields.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,33 @@ User
: Select list pre-populated with users from your User Directory.[^4]

Calculation
: Define a `formula(params)` function that returns a value using the params dictionary, which includes selected custom field keys.
: Define a `formula(params)` function that automatically calculates and returns a value based on the params dictionary, which includes selected custom field keys retrieved from your other inventory model fields.

1. Click **{{< fa plus >}}** in front of the inventory field to allow your formula access to the field's values.
2. Replace the demonstration formula with your own in the code box provided.
3. Enter in sample values in the testing area then click **{{< fa play >}} Test Formula** to validate your formula.

::: {.callout title="Stick to basic operations."}
Keep your code simple and avoid complex logic and imports.
:::

For example, say you have numeric model inventory fields of `materiality` and `complexity`, where a larger value indicates a lower risk:

![Adding a calculation type field](calculation-field.png){fig-alt="A screenshot showing the screen for adding a calculation type field" class="screenshot"}

::: {.column-margin}
```python
def formula(params):
# High Risk: If materiality is high risk, return high risk regardless of complexity
if params.materiality == "High Risk":
return "High Risk"
# Medium Risk: If materiality is low risk but complexity is high risk, return medium risk
if params.materiality == "Low Risk" and params.complexity == "High Risk":
return "Medium Risk"
# Low Risk: Both materiality and complexity are low risk
return "Low Risk"
```
:::

## Delete inventory fields

Expand Down