Settings.saveAsync method (JavaScript API for Office v1.1)

JavaScript API for Office v1.1

Persists the in-memory copy of the settings property bag in the document.

Last modified: June 12, 2014

Available in requirement sets

Settings

Office.context.document.setting.saveAsync(callback);

callback

Type: object

A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. Optional.

When the function you passed to the callback parameter executes, it receives an AsyncResult object that you can access from the callback function's only parameter.

In the callback function passed to the saveAsync method, you can use the properties of the AsyncResult object to return the following information.

Property

Use to...

AsyncResult.value

Always returns undefined because there is no object or data to retrieve.

AsyncResult.status

Determine the success or failure of the operation.

AsyncResult.error

Access an Error object that provides error information if the operation failed.

AsyncResult.asyncContext

Access your user-defined object or value, if you passed one as the asyncContext parameter.

Any settings previously saved by an app are loaded when it is initialized, so 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 app is used, use the saveAsync method.

Note Note

The saveAsync method persists the in-memory settings property bag into the document file; however, the changes to the document file itself are saved only when the user (or AutoRecover setting) saves the document to the file system.

The refreshAsync method is only useful in coauthoring scenarios (which are only supported in Word) when other instances of the same app might change the settings and those changes should be made available to all instances.

In version 1.1 of Office.js, you can create settings in content apps for Access.

function persistSettings() {
    Office.context.document.settings.saveAsync(function (asyncResult) {
        write('Settings saved with status: ' + asyncResult.status);
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

App types

Content apps, Task pane apps

Supported clients

Access app for SharePoint, Excel 2013, Excel Online, Excel 2013 SP1, Excel 2013 RT, Word 2013, Word 2013 SP1, Word 2013 RT, PowerPoint 2013, PowerPoint 2013 SP1, PowerPoint 2013 RT

Library

Office.js

Namespace

Office

Show:
© 2014 Microsoft