Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[All Hosts] (manifest) update tech background articles for unified manifest #4834

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion docs/design/contextual-tabs.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Additionally, custom contextual tabs only work on platforms that support the fol
- [SharedRuntime 1.1](/javascript/api/requirement-sets/common/shared-runtime-requirement-sets)

> [!TIP]
> Use the runtime checks in your code to test whether the user's host and platform combination supports these requirement sets as described in [Runtime checks for method and requirement set support](../develop/specify-office-hosts-and-api-requirements.md#runtime-checks-for-method-and-requirement-set-support). (The technique of specifying the requirement sets in the manifest, which is also described in that article, doesn't currently work for RibbonApi 1.2.) Alternatively, you can [implement an alternate UI experience when custom contextual tabs aren't supported](#implement-an-alternate-ui-experience-when-custom-contextual-tabs-arent-supported).
> Use the runtime checks in your code to test whether the user's host and platform combination supports these requirement sets as described in [Check for API availability at runtime](../develop/specify-api-requirements-runtime.md). (The technique of specifying the requirement sets in the manifest, which is also described in that article, doesn't currently work for RibbonApi 1.2.) Alternatively, you can [implement an alternate UI experience when custom contextual tabs aren't supported](#implement-an-alternate-ui-experience-when-custom-contextual-tabs-arent-supported).

## Behavior of custom contextual tabs

Expand Down
2 changes: 1 addition & 1 deletion docs/develop/dialog-api-in-office-add-ins.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ Because you can make multiple `messageChild` calls from the host page, but you h
> In some situations, the `messageChild` API, which is a part of the [DialogApi 1.2 requirement set](/javascript/api/requirement-sets/common/dialog-api-requirement-sets), may not be supported. For example, `messageChild` isn't supported in volume-licensed perpetual Outlook 2016 and volume-licensed perpetual Outlook 2019. Some alternative ways for parent-to-dialog-box messaging are described in [Alternative ways of passing messages to a dialog box from its host page](parent-to-dialog.md).

> [!IMPORTANT]
> The [DialogApi 1.2 requirement set](/javascript/api/requirement-sets/common/dialog-api-requirement-sets) can't be specified in the **\<Requirements\>** section of an add-in manifest. You will have to check for support for DialogApi 1.2 at runtime using the `isSetSupported` method as described in [Runtime checks for method and requirement set support](../develop/specify-office-hosts-and-api-requirements.md#runtime-checks-for-method-and-requirement-set-support). Support for manifest requirements is under development.
> The [DialogApi 1.2 requirement set](/javascript/api/requirement-sets/common/dialog-api-requirement-sets) can't be specified in the **\<Requirements\>** section of an add-in manifest. You'll have to check for support for DialogApi 1.2 at runtime using the `isSetSupported` method as described in [Check for API availability at runtime](specify-api-requirements-runtime.md). Support for manifest requirements is under development.

### Cross-domain messaging to the dialog runtime

Expand Down
81 changes: 81 additions & 0 deletions docs/develop/specify-api-requirements-runtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: Check for API availability at runtime
description: Learn how to verify at runtime that the Office application supports your add-in's API calls.
ms.topic: best-practice
ms.date: 10/30/2024
ms.localizationpriority: medium
---

# Check for API availability at runtime

If your add-in uses a specific extensibility feature for some of its functionality, but has other useful functionality that doesn't require the extensibility feature, you should design the add-in so that it's installable on platform and Office version combinations that don't support the extensibility feature. It can provide a valuable, albeit diminished, experience on those combinations.

When the difference in the two experiences consists entirely of differences in the Office JavaScript Library APIs that are called, and not in any features that are configured in the manifest, then you test at runtime to discover whether the user's Office client supports an [API requirement set](office-versions-and-requirement-sets.md). You can also [test at runtime whether APIs that aren't in a set are supported](#check-for-setless-api-support).

> [!NOTE]
> To provide alternate experiences with features that require manifest configuration, follow the guidance in [Specify Office hosts and API requirements with the unified manifest](specify-office-hosts-and-api-requirements-unified.md) or [Specify Office applications and API requirements with the add-in only manifest](specify-office-hosts-and-api-requirements.md).

## Check for requirement set support

The [isSetSupported](/javascript/api/office/office.requirementsetsupport#office-office-requirementsetsupport-issetsupported-member(1)) method is used to check for requirement set support. Pass the requirement set's name and the minimum version as parameters. If the requirement set is supported, `isSetSupported` returns `true`. The following code shows an example.

```js
if (Office.context.requirements.isSetSupported("WordApi", "1.2")) {
// Code that uses API members from the WordApi 1.2 requirement set.
} else {
// Provide diminished experience here.
// For example, run alternate code when the user's Word is
// volume-licensed perpetual Word 2016 (which doesn't support WordApi 1.2).
}
```

About this code, note:

- The first parameter is required. It's a string that represents the name of the requirement set. For more information about available requirement sets, see [Office Add-in requirement sets](/javascript/api/requirement-sets/common/office-add-in-requirement-sets).
- The second parameter is optional. It's a string that specifies the minimum requirement set version that the Office application must support in order for the code within the `if` statement to run (for example, "1.9"). If not used, version "1.1" is assumed.

> [!WARNING]
> When calling the `isSetSupported` method, the value of the second parameter (if specified) should be a string, not a number. The JavaScript parser can't differentiate between numeric values such as 1.1 and 1.10, whereas it can for string values such as "1.1" and "1.10".

The following table shows the requirement set names for the application-specific API models.

|Office application|RequirementSetName|
|---|---|
|Excel|ExcelApi|
|OneNote|OneNoteApi|
|Outlook|Mailbox|
|PowerPoint|PowerPointApi|
|Word|WordApi|

The following is an example of using the method with one of the Common API model requirement sets.

```js
if (Office.context.requirements.isSetSupported('CustomXmlParts')) {
// Run code that uses API members from the CustomXmlParts requirement set.
} else {
// Run alternate code when the user's Office application doesn't support the CustomXmlParts requirement set.
}
```

> [!NOTE]
> The `isSetSupported` method and the requirement sets for these applications are available in the latest Office.js file on the CDN. If you don't use Office.js from the CDN, your add-in might generate exceptions if you are using an old version of the library in which `isSetSupported` is undefined. For more information, see [Use the latest Office JavaScript API library](specify-office-hosts-and-api-requirements-unified.md#use-the-latest-office-javascript-api-library).

## Check for setless API support

When your add-in depends on a method that isn't part of a requirement set, called a setless API, use a runtime check to determine whether the method is supported by the Office application, as shown in the following code example. For a complete list of methods that don't belong to a requirement set, see [Office Add-in requirement sets](/javascript/api/requirement-sets/common/office-add-in-requirement-sets#methods-that-arent-part-of-a-requirement-set).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding the term "setless API" to the glossary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding the term "setless API" to the glossary.

Done


> [!NOTE]
> We recommend that you limit the use of this type of runtime check in your add-in's code.

The following code example checks whether the Office application supports `document.setSelectedDataAsync`.

```js
if (Office.context.document.setSelectedDataAsync) {
// Run code that uses `document.setSelectedDataAsync`.
}
```

## See also
- [Office requirement sets availability](office-versions-and-requirement-sets.md#office-requirement-sets-availability)
- [Specify Office hosts and API requirements with the unified manifest](specify-office-hosts-and-api-requirements-unified.md)
- [Specify Office hosts and API requirements with the add-in only manifest](specify-office-hosts-and-api-requirements.md)
Loading