> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GetTaskByStageId

> Select and lock the highest-priority task at given stage IDs with the GetTaskByStageId method of the ABBYY FlexiCapture Web Services API, returning its ID.

## What it does

Selects the task with the highest priority and opens it for processing. The selected task is locked (i.e. cannot be opened by other users).

<Warning>
  A task must be opened before any actions on the task can be performed.
</Warning>

## Definition

```
int GetTaskByStageId( int sessionId, int projectId, int[] stageIds, bool onlyPreprocessedTasks, bool onlyPrivateBatches );
```

## Parameters

<table width="100%"><tbody><tr><td><p><strong>Name</strong></p></td><td><p><strong>Type</strong></p></td><td><p><strong>Description</strong></p></td></tr><tr><td><p>sessionId</p></td><td><p>int</p></td><td><p>The ID of the connection to the Application Server</p></td></tr><tr><td><p>projectId</p></td><td><p>int</p></td><td><p>Project ID</p></td></tr><tr><td><p>stageIds</p></td><td><p>int\[]</p></td><td><p>The IDs of the stages to get task from</p></td></tr><tr><td><p>onlyPreprocessedTask</p></td><td><p>bool</p></td><td><p>The flag which determines from which tasks to select. Possible values:</p><ul><li><strong>True</strong> - select only pre-processed tasks;</li><li><strong>False</strong> - select from all tasks.</li></ul></td></tr><tr><td><p>onlyPrivateBatches</p></td><td><p>bool</p></td><td><p>The flag which determines the set of available batches. Possible values:</p><ul><li><strong>True</strong> - only batches that belong the current user or user group are available;</li><li><strong>False</strong> - all batches are available.</li></ul></td></tr></tbody></table>

## Returned value

| **Type** | **Description** |
| -------- | --------------- |
| int      | Task ID         |
