Vjeko
Vjeko

Reputation: 181

Can't share document settings between Office Online and Office 2016

We're developing Word add-in which is storing information inside document using Settings.set and Settings.get methods.

Problem can be described in following scenario:

I'm using same manifest on both clients. I've read on Settings page:

The settings created by using the methods of the Settings object are saved per add-in and per document. That is, they are available only to the add-in that created them, and only from the document in which they are saved.

I've created sample add-in via Yeoman to demonstrate this problem. Check it out here: https://github.com/Vj3k0/onedrive-test/

Any ideas?

Upvotes: 1

Views: 239

Answers (2)

Marc LaFleur
Marc LaFleur

Reputation: 33094

The Settings.set method affects only the settings in-memory. Once you have made all your changes to Settings, you'll need to call Settings.saveAsync method to persist them.

In addition, prior to reading from the settings you should rehydrate them into memory using Settings.refreshAsync.

Using your example, I made the following changes:

  Office.context.document.settings.refreshAsync(function () {

    var foo = Office.context.document.settings.get('hello');
    if (!foo) {
      Office.context.document.settings.set('hello', 'world');
      Office.context.document.settings.saveAsync(function (asyncResult) {
        $('#content').append('Settings saved with status: ' + asyncResult.status);
      });
    }
    else {
      $('#content').append('Value found: ' + foo);
    }

  });

I've published a working example on GitHub: Word-Settings-Sample

One additional note regarding side-loading of manifests. As Juan covers in his answer, to accurately test across platforms you'll need to centrally deploy your add-in. My personal preference here is to use a O365 Developer Tenant and Central Deployment for this purpose. You can obtain this for free through the Microsoft Office 365 Developer Program.

Upvotes: 3

Juan Balmori
Juan Balmori

Reputation: 5036

Office.js settings are stored per add-in instance, per document. That means, for example, that if you insert multiple content add-ins in Excel, each of them will have their own set of settings. (ultimately are different add-in instances)

In some conditions this might also happen for task pane add-ins, it depends how you test it. if you are side loading a manifest in Word Online that will have have a different ID in the file format each time you insert it, and of course the ID willl be different from an Add-in inserted in Win32 using file shared, just by the fact that it came from a different store. If you open analyze the file format (ooxml) each time you insert a task pane add-in you will see that the PK of an Add-in is the store it came from plus the ID. (that what makes an add-in instance unique)

If you are using the SharePoint catalog or the store, you will get the same instance ID and store, and settings will work as expected. If you want to test multiplatform I recommend you to use our corp deployment to test it, or ship it as preview to the store.

Check this file formats sample: it has the same taskpane inserted in Online using the sideloading feature of the insertion dialog: (note how the id is different on the same store Type, therefore settings will be saved in different instances)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<we:webextension id="f3984fd0-d21e-45a5-9353-942c4e1e3535" xmlns:we="http://schemas.microsoft.com/office/webextensions/webextension/2010/11">
    <we:reference id="42e27db6-2647-4c5a-83b3-80056035d6f8" version="1.0" store="developer" storeType="uploadfiledevcatalog" />
    <we:alternateReferences />
    <we:properties />
    <we:bindings />
    <we:snapshot xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />
</we:webextension>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<we:webextension id="1e14b918-3b58-48f2-a102-51da5c594251" xmlns:we="http://schemas.microsoft.com/office/webextensions/webextension/2010/11">
    <we:reference id="78e27db6-2647-4c5a-83b3-80056035d6f8" version="1.0" store="developer" storeType="uploadfiledevcatalog" />
    <we:alternateReferences />
    <we:properties />
    <we:bindings />
    <we:snapshot xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />
</we:webextension>

Upvotes: 2

Related Questions