Jerry Weeks Jerry Weeks - 2 months ago 41
Javascript Question

What versions of Office 2016 support Office.context.reqirements.isSetSupported()?

We are running Office 2016 16.0.6741.2063 (Deferred channel), allot of the Office 365 API works fine (some issues around using docx inserts etc, but XML is fine)

But this code always goes to "blockUI and warning (if I take out (not) "!", then it is fine, so is not an error in the rest of the code).

'WordApi' in any shape or form fails (1.2, no version, 1, 0.1 - I have tried them all!)
According to the spec 2016 should support this, but it seems the deferred channel doesn't?

Any ideas of how to make this run (or any other tips for finding office version in JavaScript)

Some of the team are on version 15..n of Office, and I am trying to use this to alert them to upgrade to 16..n to reduce the support burden!

Office.initialize = function (reason) {
$(document).ready(function () {
if (! Office.context.requirements.isSetSupported('WordApi', 1.1)){
$.blockUI({message: "This Add-In only works with versions of Office 365 greater than 16, please ring the help doesk to get your version upgraded <br/><a href='https://www.office.com/1?auth=2&home=1&from=ShellLogo'><u>Or click here for Office 365</u></a>"});
}
else {
// If setSelectedDataAsync method is supported by the host application
// the UI buttons are hooked up to call the method else the buttons are removed
if (Office.context.document.setSelectedDataAsync) {
ExecuteOrDelayUntilScriptLoaded(addDocsAsYouGo, "sp.js");
ExecuteOrDelayUntilScriptLoaded(addDocsAsYouGoDefr, "sp.js");
if(!siteInitialised){
initialiseSharePointConnection();
}
if (!pathInitiliased){
clientContext.executeQueryAsync(function () {
filePath = oWebsite.get_serverRelativeUrl() + "/Shared Documents/addin/ContentDOCX/";
pathInitiliased = true;
});
}
}
}
});
};

Answer

All versions of the Add-in-enabled clients support this (i.e., 2013, 2016, Mac, Online, etc. etc.) You'll have to agree that it would be rather ironic (and catch-22) to require that you know what client you're on, in order to query the API that will [effectively] tell you what client you're on.

If you're not seeing this work, please check what version of Office.js you're using. The API was added in a way that retroactively makes it work for Office 2013 (which shipped without this), but you have to be using the latest (or close to) version of Office.js. Referencing the CDN would be the best way to guarantee this.

<script src="https://appsforoffice.microsoft.com/lib/1/hosted/Office.js" type="text/javascript"></script>
Comments