---
title: "Result"
description: "Generic operation result with success flag, data, and an error map. Analogue of \\\\Bitrix\\\\Main\\\\Result from the Bitrix Framework."
canonical_url: "https://bitrix24.github.io/b24jssdk/docs/working-with-the-rest-api/core-result"
last_updated: "2026-07-03"
---
# Result

> Generic operation result with success flag, data, and an error map. Analogue of \\Bitrix\\Main\\Result from the Bitrix Framework.

`Result<T>`{className="language-ts-type shiki shiki-themes material-theme-lighter material-theme material-theme-palenight" language="ts-type" style=""} is the SDK's uniform return type for higher-level helpers (`callBatch`, `B24HelperManager.loadData`, `OptionsManager.save`, …). The class implements `IResult<T>`{className="language-ts-type shiki shiki-themes material-theme-lighter material-theme material-theme-palenight" language="ts-type" style=""}; the typed REST helpers (`call.make`, `callList.make`, …) return its specialised subclass [`AjaxResult<T>`](https://bitrix24.github.io/b24jssdk/raw/docs/working-with-the-rest-api/core-ajax-result.md).

## Usage

```ts
import { Result } from '@bitrix24/b24jssdk'

function parseConfig(raw: string): Result<{ theme: string }> {
  try {
    const data = JSON.parse(raw)
    if (typeof data?.theme !== 'string') {
      return Result.fail<{ theme: string }>('theme is required', 'config:theme')
    }
    return Result.ok({ theme: data.theme })
  } catch (error) {
    return Result.fail<{ theme: string }>(error as Error, 'config:json')
  }
}

function applyConfig() {
  const rawJson = '{"theme":"light"}'
  const result = parseConfig(rawJson)
  if (!result.isSuccess) {
    console.error(result.getErrorMessages())
    return
  }
  const { theme } = result.getData()!
  console.log('theme:', theme)
}
applyConfig()
```

## Constructor

```ts-type
new Result<T>(data?: T)
```

Default `data` is `null`{className="language-ts-type shiki shiki-themes material-theme-lighter material-theme material-theme-palenight" language="ts-type" style=""}.

## Static Factories

```ts-type
Result.ok<U>(data?: U): Result<U>
Result.fail<U>(error: Error | string, key?: string): Result<U>
```

## Getters

| Getter | Type | Description |
| --- | --- | --- |
| `isSuccess` | `boolean`{className="language-ts-type shiki shiki-themes material-theme-lighter material-theme material-theme-palenight" language="ts-type" style=""} | `true` when the error map is empty. |
| `errors` | `Map<string, Error>`{className="language-ts-type shiki shiki-themes material-theme-lighter material-theme material-theme-palenight" language="ts-type" style=""} | Underlying error storage (read-only by convention). |

## Data Methods

```ts-type
setData(data: T | null | undefined): Result<T>
getData(): T | null | undefined
```

`setData` is chainable. Note: `AjaxResult`{className="language-ts-type shiki shiki-themes material-theme-lighter material-theme material-theme-palenight" language="ts-type" style=""} **disables** `setData` and throws `ReferenceError`{className="language-ts-type shiki shiki-themes material-theme-lighter material-theme material-theme-palenight" language="ts-type" style=""} on call.

## Error Methods

```ts-type
addError(error: Error | string, key?: string): Result<T>
addErrors(errors: (Error | string)[]): Result<T>
hasError(key: string): boolean
getErrors(): IterableIterator<Error>
getErrorMessages(): string[]
getErrorsByKey(): Record<string, Error>
getErrorMessagesByKey(): Record<string, string>
```

When `key` is omitted, `addError` generates a UUID v7 via [`Text.getUuidRfc4122()`](https://bitrix24.github.io/b24jssdk/raw/docs/working-with-the-rest-api/tools-text.md) so duplicate strings still get distinct slots.

`getErrorsByKey()` / `getErrorMessagesByKey()` return a `Record`{className="language-ts-type shiki shiki-themes material-theme-lighter material-theme material-theme-palenight" language="ts-type" style=""} **snapshot** keyed by that identifier, so you can tell which call failed — unlike `getErrors()` / `getErrorMessages()`, which drop the keys, and unlike the live `errors` `Map`{className="language-ts-type shiki shiki-themes material-theme-lighter material-theme material-theme-palenight" language="ts-type" style=""} getter. For batches the key tells you which command failed: an **object / named-command** batch keys by the command label, and an **array-mode** batch keys by the command's **numeric position** (`'0'`, `'1'`, … — since v1.4.0 / [#255](https://github.com/bitrix24/b24jssdk/issues/255){rel="[\"nofollow\"]"}; previously these were random UUIDs). An envelope-level soft error not tied to one command uses the internal `base-error` key, and `addErrors()` (no explicit key) still uses generated UUIDs — for those, prefer `getErrors()` / `getErrorMessages()`.

```ts
const res = await $b24.actions.v2.batch.make({
  calls: {
    contact: { method: 'crm.item.get', params: { entityTypeId: 3, id: 1 } },
    deal: { method: 'crm.item.get', params: { entityTypeId: 2, id: 999 } }
  },
  options: { isHaltOnError: false }
})
if (!res.isSuccess) {
  console.error(res.getErrorMessagesByKey()) // e.g. { deal: 'Access denied' }
}
```

## `toString`

```ts-type
toString(): string
```

Pretty-prints the result for logs:

- success → `Result(success): {<data JSON>}`
- failure → `Result(failure): {<data JSON>}\nErrors: <messages joined by ", ">`

`Error` instances inside the data are serialised as `{ name, message, stack }`. Failure to stringify falls back to `'[Unable to serialize data]'`.

## Sitemap

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