> For the complete documentation index, see [llms.txt](https://docs.docbits.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docbits.com/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits/sample-scripts/task-high-amount.md).

# Task for High Amount

## What does this script do?

Creates an approval task when the invoice total exceeds a threshold (e.g., 100,000). The task is assigned to the "Finance Approval" group and triggers an email notification to ensure timely review.

## Trigger

`AFTER_FORMATTING` on document type **INVOICE**

## Full Script

```python
# Read total amount from the document
total = get_field_value(document_data, "total_amount", "0")

try:
    if float(total) > 100000:
        # Find the Finance Approval group by name
        finance_group = get_group_by_name(org_id, "Finance Approval")

        # Create an approval task
        create_document_task(
            user,
            document_data,
            title="Amount > 100,000 - Approval required",
            description=f"Total amount: {total}",
            priority="HIGH",
            assigned_to_user_id=None,
            assigned_to_group_id=str(finance_group.id) if finance_group else None,
            send_email=True
        )
except ValueError:
    pass
```

## Step-by-Step Explanation

1. **Read total amount** from the document
2. **Check threshold** — only proceed if amount exceeds 100,000
3. **Find group** by name using `get_group_by_name()` to get the group ID dynamically
4. **Create task** assigned to the finance group with high priority and email notification

## Functions Used

* [get\_field\_value()](/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits/field-functions.md#get_field_value) — Read field value
* [get\_group\_by\_name()](/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits/business-logic-functions.md#get_group_by_id--get_group_by_name) — Find group by name
* [create\_document\_task()](/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits/business-logic-functions.md#create_document_task) — Create approval task


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.docbits.com/administration-and-setup/settings/global-settings/document-types/script/scripting-in-docbits/sample-scripts/task-high-amount.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
