Export (0) Print
Expand All

Settings.saveAsync method (JavaScript API for Office)

apps for Office

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

Last modified: April 22, 2015

Note Note

The name "apps for Office" is changing to "Office Add-ins". During the transition, the documentation and the UI of some Office host applications and Visual Studio tools might still use the term "apps for Office".

Hosts:

Access, Excel, PowerPoint, Word

Available in Requirement set

Settings

Last changed in

1.1

See all support details

Office.context.document.settings.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.

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; 
}

A checkmark (√) in the following matrix indicates that this method is supported in the corresponding Office host application. An empty cell indicates that the Office host application doesn't support this method.

For more information about Office host application and server requirements, see Requirements for running apps for Office.

Office for Windows desktop

Office for Windows RT

Office Online
(in browser)

Access

Excel

PowerPoint

Word

Available in requirement sets

Settings

Minimum permission level

Restricted

App types

Content, task pane

Library

Office.js

Namespace

Office

Version

Changes

1.1

Added support for custom settings in content apps for Access.

1.0

Introduced

Show:
© 2015 Microsoft