---
title: "Task automation on stage transitions"
description: "Poll deal stages every 60 s. When a watched transition fires, create a task with description, deadline and priority."
canonical_url: "https://bitrix24.github.io/b24jssdk/docs/examples/task-automation"
last_updated: "2026-06-02"
---
# Task automation on stage transitions

> Poll deal stages every 60 s. When a watched transition fires, create a task with description, deadline and priority.

## What it does

Loads open deals (excluding `WON`/`LOSE`) every minute, compares each stage with the previously seen value, and on each watched transition (`EXECUTING`, `PREPAYMENT_INVOICE`, `FINAL_INVOICE` by default) creates a task bound to the deal via `UF_CRM_TASK`.

## Stack

Node.js 18+. No external dependencies.

## Environment

```bash
export B24_HOOK='https://your.bitrix24.com/rest/1/secret'
```

## Run

```bash
npx tsx 03-task-automation.ts
```

## Source

[`skills/b24jssdk-recipes/examples/03-task-automation.ts`](https://github.com/bitrix24/b24jssdk/blob/main/skills/b24jssdk-recipes/examples/03-task-automation.ts).

## Notes

- State (`dealStages`) is held in memory. Restart loses it by design — for production persist to disk or Redis.
- Polling is wasteful at scale; the Pull-driven variant (subscribe to `'crm'` events) is on the suggestion list.
- Multi-funnel portals: the recipe uses a `baseStage()` helper to match `C<n>:EXECUTING`, etc.

## Sitemap

See the full [sitemap](/b24jssdk/sitemap.md) for all pages.
