# Using AdapTable in OpenFin

Canonical page: https://www.adaptabletools.com/docs/integrations-openfin

- The OpenFin Plugin provides extra functionality for users when AdapTable is running in the [OpenFin](https://openfin.co/) container

The OpenFin Plugin is intended for use when AdapTable is instantiated inside the [OpenFin](https://openfin.co/) container.

- In June 2024 OpenFin was renamed as here
- All existing functionality remains unchanged (but we are exploring new possibilities...)

This plugin allows users to take advantage of some additional functionality courtesy of OpenFin:

- AdapTable's [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md) can appear as OpenFin Notifications (together with actionable buttons)
- 'Live Excel' - where data exported to Excel updates in the spreadsheet in real time as the source data in AdapTable itself ticks

## Installing OpenFin Plugin

npm install @adaptabletools/adaptable-plugin-openfin

If [using CommonJS](https://www.adaptabletools.com/docs/getting-started-installation/index.md#esm-and-cjs-formats), then install `@adaptabletools/adaptable-plugin-openfin-cjs` instead

AdapTable users who are also using OpenFin are able to benefit from additional features.

This is provided via a dedicated OpenFin Plugin

[OpenFin](https://openfin.co/) describes itself as:

<i>
the OS for Enterprise Productivity. We bring organizations together in a single, secure, and unified workspace. From the world’s largest banks to emerging startups around the world, OpenFin is being used by firms of all sizes to build beautiful desktop applications and custom end-user workspaces that drive productivity.
</i>

OpenFin also provides full FDC3 functionality which [AdapTable works with seamlessly](https://www.adaptabletools.com/docs/handbook-fdc3/index.md).

## Configuring OpenFin Plugin

Setting up the OpenFin Plugin is similar to all other [Plugins](https://www.adaptabletools.com/docs/technical-reference-plugins/index.md) in AdapTable.

Developers supply details in the plugins section of [Adaptable Options](https://www.adaptabletools.com/docs/technical-reference-adaptable-options/index.md).

They use [OpenFin Plugin Options](https://www.adaptabletools.com/docs/technical-reference-openfin/index.md) to specify optional configuration settings for running the OpenFin Plugin.

### Setting Up the OpenFin Plugin

To set up the plugin and access the [OpenFin API](https://www.adaptabletools.com/docs/technical-reference-openfin/index.md), follow these steps:

You need to reference 3 Services in your OpenFin.json which are leveraged by AdapTable to provide additional functionality:

- excel
- notifications
- fdc3

Ensure that the provided value is unique

```json
  "services": [
    {
      "name": "excel",
      "manifestUrl": "https://cdn.openfin.co/release/exceljs/4.0.1/provider/app.json"
    },
    {
      "name": "notifications"
    },
    {
      "name": "fdc3"
    }
  ],
```

Make sure to import the file in your app.

```ts
import openfin from '@adaptabletools/adaptable-plugin-openfin';
```

Make sure to import the file in your app.

```ts
import {OpenFinApi} from '@adaptabletools/adaptable';
```

Create an [OpenFinPluginOptions](https://www.adaptabletools.com/docs/technical-reference-openfin/index.md) if required.

Provide the necessary properties.

```ts
const openfinPluginOptions: OpenFinPluginOptions = {
  notificationTimeout: false,
  showApplicationIconInNotifications: true,
};
```

Specify the plugin in Adaptable Options.

Pass into the plugin any Options defined in previous step.

```ts
const adaptableOptions: AdaptableOptions = {
  adaptableId: 'openfindemo',
  plugins: [openfin(openfinPluginOptions)],
};
```

Get hold of a reference to the [OpenFin API](https://www.adaptabletools.com/docs/technical-reference-openfin/index.md) for future use.

```ts
const openfinApi: OpenFinApi = api.pluginsApi.getOpenFinPluginApi();
```

## OpenFin Toolbar

The OpenFin Plugin makes a dedicated [Toolbar](https://www.adaptabletools.com/docs/ui-dashboard/index.md#tabs-and-toolbars) called 'OpenFin' available.

This makes it possible to run [Live Reports](#live-reports) in Excel

The Toolbar can be referenced in [Dashboard Initial State](https://www.adaptabletools.com/docs/technical-reference-dashboard/index.md) as follows:

```ts
const initialState: InitialState = {
  Dashboard: {
    Tabs: [
      {
        Name: 'Dashboard Toolbars',
        Toolbars: ['Layout', 'OpenFin', 'Export'],
      },
    ],
  },
};
```

## Live Reports

One feature available when AdapTable is running in the OpenFin Plugin is Live Export via Excel.

This enables grid data to be sent from AdapTable to Excel with **2 way updates**:

Any Reports created in the [Export](https://www.adaptabletools.com/docs/handbook-exporting/index.md) Module will automatically appear in the OpenFin Toolbar

- Excel will automatically update in line with cell edits and ticking data changes in AdapTable
- Any date edits made directly in Excel will be automatically reflected in AdapTable

Live Reports are started and stopped from the OpenFin toolbar. To schedule a standard AdapTable [Report](https://www.adaptabletools.com/docs/handbook-exporting/index.md) export, use [Scheduling](https://www.adaptabletools.com/docs/handbook-exporting-scheduling/index.md) from the Export module (not from the OpenFin toolbar).

To make this functionality available, specify the following in the app.json file:

```json
"services": [
    { "name": "excel",
        "manifestUrl": "http://openfin.github.io/excel-api-example/provider/app.json"
    }
]
```

### Validating Excel Changes

The [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md) Module in AdapTable enables custom Rules to be provided to perform validation after each Data Change in the Grid.

When running Live Reports these validation rules can be extended to edits made in Excel, by setting the `onValidationFailureInExcel` property in [OpenFinPluginOptions](https://www.adaptabletools.com/docs/technical-reference-openfin/index.md).

This property can take one of 3 values:

- **override**: automatically updates Excel with the previous value (i.e. before the edit was made)

- **show-notification**: displays an OpenFin Notification explaining that the edit in Excel broke validation

- **show-undo-notification**: displays an OpenFin Notification containing a button; when clicked AdapTable will override the edit in Excel with the previous cell value

## OpenFin Notifications

AdapTable will automatically convert [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md)(set to show as Popup) into [OpenFin Notifications](https://www.npmjs.com/package/openfin-notifications).

When this happens all Alert Buttons become OpenFin Notification Action Buttons

AdapTable will display the Alert as an OpenFin Notification (using the same message type).

Turn this off by setting `showAdaptableAlertsAsNotifications` to _false_ in [OpenFin Plugin Options](https://www.adaptabletools.com/docs/technical-reference-openfin/index.md)

### Managing Notifications

Two properties in [OpenFinPluginOptions](https://www.adaptabletools.com/docs/technical-reference-openfin/index.md) help to manage how OpenFin notifications will look and work:

- **notificationTimeout** - when OpenFin notifications will expire after being displayed

- **showAppIconInNotifications** - displays App Icon (supplied in [User Interface Options](https://www.adaptabletools.com/docs/technical-reference-ui/index.md)) in the Notification

Most of the time AdapTable Alerts will appear seamlessly as OpenFin Notifications with no extra work required.

However 2 properties (both JavaScript functions) are available for when greater control over the look and feel or functionality of a Notification is required:

- **onNotificationAction** - function invoked when a button in an OpenFin notification is clicked

- **onShowNotification** - function which custom updates an OpenFin notification before it is displayed

## FDC3

OpenFin was a founder member of FDC3 and provides [comprehensive FDC3 support](https://www.openfin.co/fdc3/).

This means that anyone using AdapTable with OpenFin can utilise AdapTable's [FDC3 features](https://www.adaptabletools.com/docs/handbook-fdc3/index.md).

## UI Entitlements

OpenFin only works if it's [Entitlement](https://www.adaptabletools.com/docs/handbook-permissioning/index.md) is set to **Full** and the plugin was correctly set up and installed.

The `ReadOnly` Entitlement behaviour is the same as if the Access Level was `Hidden`

### FAQ

**Do I need to use the OpenFin plugin to use FDC3 in OpenFin?**
No, if you only want to use FDC3 then AdapTable's comprehensive [FDC3 features](https://www.adaptabletools.com/docs/handbook-fdc3/index.md) are all you require.
Use the OpenFin Plugin if you also want features like Live Reports and OpenFin Notifications.
