-
Notifications
You must be signed in to change notification settings - Fork 252
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
Rick-Kirkham
wants to merge
8
commits into
main
Choose a base branch
from
unified-manifest-tech
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0e45d55
[All Hosts] (manifest) update tech background articles for unified ma…
Rick-Kirkham 2ced768
Merge branch 'main' into unified-manifest-tech
Rick-Kirkham 57eea9b
link fixes
Rick-Kirkham 334b032
Merge branch 'unified-manifest-tech' of https://github.com/OfficeDev/…
Rick-Kirkham 68d688c
Apply suggestions from code review
Rick-Kirkham 4b2bad3
Update docs/develop/specify-office-hosts-and-api-requirements-unified.md
Rick-Kirkham 27bbc3b
add glossary entry
Rick-Kirkham 1e61ab0
Update docs/toc.yml
Rick-Kirkham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
|
||
> [!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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done