EsPl
EsPl

Reputation: 182

Word Addin - how to check if the createDocument() function is available?

I am using Office JS to develop a Word addin.

Thanks to previous answers, I found that I can open a new document in Word by doing:

context.application.createDocument().open();

However, that seems to only work on the Desktop version of Office.

If I try that same addin in the online version, I get an error:

Sorry, this function isn’t available. Perform a runtime check on the Office add-in to find out whether the feature is supported by the host

How can I programatically find out if that function is available so that I can make the plugin default to a different behavior if it's not?

Also, is there some documentation on the createDocument function? (I googled and could not find anything).

Upvotes: 2

Views: 800

Answers (1)

Michael Zlatkovsky
Michael Zlatkovsky

Reputation: 8670

In the general case, you should use the isSetSupported API check at runtime to be able to see whether a particular method is available. See https://dev.office.com/docs/add-ins/develop/office-js-versioning

In this particular case, you're running into the fact that createDocument is part of a not-yet-released (preview-only) WordApi 1.4 (PREVIEW) API set (you can see it in the IntelliSense, both in the d.ts file (TypeScript) and vsdoc (JavaScript in VS 2015 and earlier). For example, in https://github.com/OfficeDev/office-js/blob/beta/dist/office.d.ts

enter image description here

Because it's Preview, this unfortunately means that isSetSupported will return "false" regardless... because it simply might not be reliably available anywhere yet (or at least, the team has not signed off on it being done and available). So for these Preview APIs, it's really meant just for your own dev testing, not anything you would use in production.

Upvotes: 2

Related Questions