Search code examples
javascriptoutlookoutlook-addinoutlook-web-addinsoutlook-restapi

Outlook add-in Storage for settings


I've been trying to use

Office.context.roamingSettings.set("keyVal", value)
Office.context.roamingSettings.get("keyVal")

To save in storage, but it only work for the current session. Now I've been trying to the saveAsync. But it doesn't take parameters. So I wanna how it supposed to be used. And also if it keeps the data in all platforms for the user(OWA, mobile, and Desktop)

Office.context.roamingSettings.saveAsync(function (result) {
        if (result.status !== Office.AsyncResultStatus.Succeeded) {
          console.error(`Action failed with message ${result.error.message}`);
        } else {
          console.log(`Settings saved with status: ${result.status}`);
        }
      });

Solution

  • During the lifetime of the session you can just use the set and get methods to work with the in-memory copy of the settings property bag.

    When you want to persist the settings so that they are available the next time the add-in is used, use the saveAsync method to save the settings after calling the set method. For an example see this code snippet: https://github.com/OfficeDev/office-js-snippets/blob/main/samples/outlook/10-roaming-settings/roaming-settings.yaml