Settings.saveAsync method
Persists the in-memory copy of the settings property bag in the document.
| Hosts: | Access, Excel, PowerPoint, Word |
| Available in Requirement set | Settings |
| Last changed in | 1.1 |
Office.context.document.settings.saveAsync(callback);
Parameters
callback
Type: object
A function that is invoked when the callback returns, whose only parameter is of type AsyncResult. Optional.
Callback Value
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. |
Remarks
Any settings previously saved by an add-in 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 add-in is used, use the saveAsync method.
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 add-in might change the settings and those changes should be made available to all instances.
Example
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;
}
Support details
A capital Y 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 Office Add-ins.
| Office for Windows desktop | Office Online (in browser) | Office for iPad | |
|---|---|---|---|
| Access | Y | ||
| Excel | Y | Y | Y |
| PowerPoint | Y | Y | Y |
| Word | Y | Y | Y |
| Available in requirement sets | Settings |
| Minimum permission level | Restricted |
| Add-in types | Content, task pane |
| Library | Office.js |
| Namespace | Office |
Support history
| Version | Changes |
|---|---|
| 1.1 | Added support for PowerPoint Online. |
| 1.1 | Added support for Excel, PowerPoint, and Word in Office for iPad. |
| 1.1 | Added support for custom settings in content add-ins for Access. |
| 1.0 | Introduced |