4

I am using the Settings Object of the JavaScript API in a Task Pane App to save some key-value pairs in the document.

My code is something like this

 Office.context.document.settings.set(key, value);
 Office.context.document.settings.saveAsync(function () {
        Toast.showToast("Setting saved", "Info saved into the document using saveAsync");
 });

I am also calling the saveAsync function on it to persist the value.

The problem I am facing is that settings are not being persisted in Word Online as currently settings Object is not supported in Word Online

So is there a way to find that the application is Running in Word Online, so a message could be displayed, or localStorage or something else can be used to save values.

Edit: Created a uservoice request to add this in Word Online, you can support this feature here

Edit 2

To better explain the problem and share an example, I have created a sample addon, the manifest is located here.

Here you can type the value for the key test and press save, this internally calls the function saveToPropertyBag(key, value) located in StorageLibrary.js . This function has the above mentioned code to save the setting and then saveAsync is called so the values get persisted in the document.

Now you can refresh the browser or reload the addon, and press get, the value will be available in Excel and Powerpoint but not in Word Online.

So I am looking a way to detect the host(Word Online) so that I can fall back to alternate way to store the value like local Storage and also display a warning to user.

Shiva
  • 6,677
  • 4
  • 36
  • 61

1 Answers1

3

See my answer to Neat ways to get environment (i.e. Office version)

Essentially, you should be able to call

if (Office.context.requirements.isSetSupported("Settings", 1.1)) {
    // Use Office settings
} else {
    // Fall back to local storage or something else.
}

~ Michael Zlatkovsky
   Developer on Office Extensibility team, MSFT

Community
  • 1
  • 1
  • `Office.context.requirements.isSetSupported("Settings", 1.1)` return true in the WordOnline client although Settings is not supported in it – Shiva Oct 29 '15 at 07:16
  • @Shiva, I am very very suprised to hear it. Could you describe what exactly you mean by "Settings is not supported in it". What method are you trying to call? The reason I ask is that, as you can see in https://msdn.microsoft.com/en-us/library/office/dn535871.aspx, the Settings requirement set includes only some of the members under Settings -- namely, get, remove, saveAsync, and set. There are a number of others -- addHandlerAsync, refreshAsync, and removeHandlerAsync that are NOT part of the requirement set, and which you'd need to check in a different way. But which one are you calling? – Michael Zlatkovsky - Microsoft Oct 29 '15 at 14:48
  • On re-reading your question, sounds like you are trying to call just saveAsync? That is absolutely supposed to be supported (an in fact, even the MSDN article linked above shows it as supported for Word Online). Let me see if it's a bug... – Michael Zlatkovsky - Microsoft Oct 29 '15 at 15:34
  • In this documentation msdn.microsoft.com/en-us/library/office/… it mentions that Settings is not supported in Word Online. Yes I am setting some key values in settings and calling saveAsync and its successfully getting saved, now if you refresh the browser and try to retrieve the value its not being retrieved in Word Online, I have Edited the question please have a look. thanks for the support. – Shiva Oct 29 '15 at 17:40
  • 1
    @Shiva, ok, thanks for the clarification. This sounds like a bug. I am escalating it to the proper engineers within my team. – Michael Zlatkovsky - Microsoft Oct 29 '15 at 18:03
  • Thanks ! Please feel free to contact me if any additional code/test case is required here on SO or on my email `shivasaxena@outlook.com` – Shiva Oct 29 '15 at 18:53
  • 1
    This bug is fixed; please let us know if you encounter more issues here. Thanks! – Michael Saunders Jan 12 '16 at 19:40