# GC.Spread.Sheets.Scenarios.ScenarioManager

## Content

# Class: ScenarioManager

[Sheets](../modules/GC.Spread.Sheets).[Scenarios](../modules/GC.Spread.Sheets.Scenarios).ScenarioManager

## Table of contents

### Constructors

- [constructor](GC.Spread.Sheets.Scenarios.ScenarioManager#constructor)

### Methods

- [all](GC.Spread.Sheets.Scenarios.ScenarioManager#all)
- [apply](GC.Spread.Sheets.Scenarios.ScenarioManager#apply)
- [get](GC.Spread.Sheets.Scenarios.ScenarioManager#get)
- [getAppliedScenarios](GC.Spread.Sheets.Scenarios.ScenarioManager#getappliedscenarios)
- [getBaseValues](GC.Spread.Sheets.Scenarios.ScenarioManager#getbasevalues)
- [remove](GC.Spread.Sheets.Scenarios.ScenarioManager#remove)
- [restore](GC.Spread.Sheets.Scenarios.ScenarioManager#restore)
- [set](GC.Spread.Sheets.Scenarios.ScenarioManager#set)
- [setActiveScenario](GC.Spread.Sheets.Scenarios.ScenarioManager#setactivescenario)

## Constructors

### <a id="constructor" name="constructor"></a> constructor

• **new ScenarioManager**(`workbook`)

Represents a scenario manager for retrieving, updating, removing, applying, restoring, and active, deactive scenarios in a workbook.

**`example`**
```javascript
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var scenarioManager = spread.scenarioManager;
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `workbook` | [`Workbook`](GC.Spread.Sheets.Workbook) | The workbook that owns the scenario manager. |

## Methods

### <a id="all" name="all"></a> all

▸ **all**(): [`IScenario`](../interfaces/GC.Spread.Sheets.Scenarios.IScenario)[]

Gets all scenarios in the workbook.

**`example`**
```javascript
var scenarios = spread.scenarioManager.all();
console.log(scenarios.length);
```

#### Returns

[`IScenario`](../interfaces/GC.Spread.Sheets.Scenarios.IScenario)[]

All scenarios in the workbook.

___

### <a id="apply" name="apply"></a> apply

▸ **apply**(`name`): `boolean`

Applies a scenario to the workbook.

**`example`**
```javascript
spread.scenarioManager.apply("Optimistic");
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The scenario name. |

#### Returns

`boolean`

`true` if the scenario is applied successfully; otherwise, `false`.

___

### <a id="get" name="get"></a> get

▸ **get**(`name`): `undefined` \| [`IScenario`](../interfaces/GC.Spread.Sheets.Scenarios.IScenario)

Gets a scenario by name.

**`example`**
```javascript
var scenario = spread.scenarioManager.get("Optimistic");
console.log(scenario);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The scenario name. |

#### Returns

`undefined` \| [`IScenario`](../interfaces/GC.Spread.Sheets.Scenarios.IScenario)

The scenario with the specified name. Returns `undefined` if the scenario does not exist.

___

### <a id="getappliedscenarios" name="getappliedscenarios"></a> getAppliedScenarios

▸ **getAppliedScenarios**(): `string`[]

Gets the names of scenarios that are currently applied and not yet restored.

**`example`**
```javascript
var appliedNames = spread.scenarioManager.getAppliedScenarios();
console.log(appliedNames);
```

#### Returns

`string`[]

The applied scenario names in application order.

___

### <a id="getbasevalues" name="getbasevalues"></a> getBaseValues

▸ **getBaseValues**(): [`IOverrides`](../interfaces/GC.Spread.Sheets.Scenarios.IOverrides)[]

Gets a read-only snapshot of the current scenario base values.

**`example`**
```javascript
var baseValues = spread.scenarioManager.getBaseValues();
console.log(baseValues);
```

#### Returns

[`IOverrides`](../interfaces/GC.Spread.Sheets.Scenarios.IOverrides)[]

The current base values.

___

### <a id="remove" name="remove"></a> remove

▸ **remove**(`name?`): `void`

Removes a scenario by name. If no name is provided, all scenarios in the workbook are removed.

**`example`**
```javascript
spread.scenarioManager.remove("Optimistic");
// Or remove all scenarios:
spread.scenarioManager.remove();
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name?` | `string` | The scenario name. If omitted, all scenarios are removed. |

#### Returns

`void`

___

### <a id="restore" name="restore"></a> restore

▸ **restore**(`name?`): `void`

Restores previously applied scenario values to their base values.

**`example`**
```javascript
spread.scenarioManager.restore("Optimistic");
// Or restore all applied scenarios:
spread.scenarioManager.restore();
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name?` | `string` | The scenario name. If omitted, all applied scenarios are restored. |

#### Returns

`void`

___

### <a id="set" name="set"></a> set

▸ **set**(`scenario`): `void`

Updates an existing scenario definition.

**`example`**
```javascript
var scenario = spread.scenarioManager.get("Optimistic");
if (scenario) {
    scenario.overrides[0].comment = "Updated sales growth assumption.";
    spread.scenarioManager.set(scenario);
}
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `scenario` | [`IScenario`](../interfaces/GC.Spread.Sheets.Scenarios.IScenario) | The scenario definition to update. |

#### Returns

`void`

___

### <a id="setactivescenario" name="setactivescenario"></a> setActiveScenario

▸ **setActiveScenario**(`name`): `boolean`

Activates a scenario to capture subsequent cell value edits, or deactivates the current active scenario.

**`example`**
```javascript
spread.scenarioManager.setActiveScenario("Optimistic");
activeSheet.setValue(1, 1, 1200);
spread.scenarioManager.setActiveScenario(null);
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `name` | ``null`` \| `string` | The scenario name. Pass `null` to deactivate the current active scenario. |

#### Returns

`boolean`

`true` if the operation succeeds; otherwise, `false`.
