Options

This is a collection of key/value pairs separated by a colon.
The key is the name of the parameter.
The value is the data that you want to use for that parameter.


Examples - Document.getSelectedDataAsync

Office.context.document.getSelectedDataAsync(Office.CoercionType _coerciontype 
                                             [, Object _options]
                                             [, function _callback])

_coerciontype - The type of data that you want to get.
_options - This is a collection of key/value pairs seperated by a colon.
_callback - This is invoked once the aysnchronous operation is complete.


Office.context.document.setSelectedDataAsync(Object _data 
                                             [, Object _options]
                                             [, function _callback])

_data - This is the value that you want to set.
_options - This is a collection of key/value pairs separated by a colon.
_callback - This is invoked once the aysnchronous operation is complete.


Parameter / Value Pairs

The values can be any javascript data type:
String, Number, Boolean, Object, Array, Null, undefined


Each function has a list of specific parameters that are available
The optional parameters for the getSelectedDataAsync are:


NameTypeDescription
valueFormatValueFormatSpecifies whether to return the result with its number of date values formatted or unformatted.
Office.ValueFormat.Formatted
Office.ValueFormat.Unformatted
filterTypeFilterTypeSpecifies whether to apply filtering when the data is returned.
asyncContextanySpecifies a user defined item that can be accessed from the asyncResult object.

The common syntax for all "Async" methods follows this pattern:
AsyncMethod ( RequiredParameters , [ OptionalParameters ], CallbackFunction );
All asynchronous methods support optional parameters, which are passed in as a JavaScript Object Notation (JSON) object that


contains one or more optional parameters. The JSON object containing the optional parameters is an unordered collection of


key-value pairs with the ":" character separating the key and the value. Each pair in the object is comma-separated, and the


entire set of pairs is enclosed in braces. The key is the parameter name, and value is the value to pass for that parameter.
You can create the JSON object that contains optional parameters inline, or by creating an options object and passing that


in as the options parameter.



* Passing optional parameters inline
For example, the syntax for calling the Document.setSelectedDataAsync method with optional parameters inline looks like this:
Office.context.document.setSelectedDataAsync(data, {coercionType: 'coercionType', asyncContext:' asyncContext},callback);
In this form of the calling syntax, the two optional parameters, coercionType and asyncContext, are defined as a JSON object


inline enclosed in braces.
The following example shows how to call to the Document.setSelectedDataAsync method by specifying optional parameters inline.


hello world /body-html>", {coercionType: "html", asyncContext: 42}, function(asyncResult) { write(asyncResult.status + " " + asyncResult.asyncContext); } )


// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message;
}
Note: You can specify optional parameters in any order in the JSON object as long as their names are specified correctly



* Passing optional parameters in an options object
Alternatively, you can create an object named options that specifies the optional parameters separately from the method


call, and then pass the options object as the options argument.
The following example shows one way of creating the options object, where parameter1, value1, and so on, are placeholders


for the actual parameter names and values.
var options = {
parameter1: value1,
parameter2: value2,
...
parameterN: valueN
};


Which looks like the following example when used to specify the ValueFormat and FilterType parameters.
var options = {
valueFormat: "unformatted",
filterType: "all"
};
Here's another way of creating the options object.
var options = {};
options[parameter1] = value1;
options[parameter2] = value2;
...
options[parameterN] = valueN;
Which looks like the following example when used to specify the ValueFormat and FilterType parameters.:
var options = {};
options["ValueFormat"] = "unformatted";
options["FilterType"] = "all";
Note When using either method of creating the options object, you can specify optional parameters in any order as long as


their names are specified correctly



The following example shows how to call to the Document.setSelectedDataAsync method by specifying optional parameters in an


options object.
var options = {
coercionType: "html",
asyncContext: 42
};


document.setSelectedDataAsync(
"html-body hello world body-html",
options,
function(asyncResult) {
write(asyncResult.status + " " + asyncResult.asyncContext);
}
)


// Function that writes to a div with id='message' on the page.
function write(message){
document.getElementById('message').innerText += message;
}
In both optional parameter examples, the callback parameter is specified as the last parameter (following the inline


optional parameters, or following the options argument object). Alternatively, you can specify the callback parameter inside


either the inline JSON object, or in the options object. However, you can pass the callback parameter in only one location:


either in the options object (inline or created externally), or as the last parameter, but not both



© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext