Bindings.addFromPromptAsync method (JavaScript API for Office v1.0)

Displays UI that enables the user to specify a selection to bind to.

Last modified: June 12, 2014

_bindingsObj.addFromPromptAsync(bindingType [, options], callback);

bindingType

Type: BindingType

Specifies the type of the binding object that should be returned when the bound object is retrieved. Required.

Returns null if the selected object cannot be coerced into the specified type.

options

Type:object

Specifies the following optional parameters.

id

Type: string

Specifies the unique name to be used to identify the binding object. Optional.

If no id argument is passed, an id will be autogenerated.

promptText

Type: string

Specifies the string to display in the prompt UI that tells the user what to select. Limited to 200 characters. Optional.

If no promptText argument is passed, "Please make a selection" is displayed.

asyncContext

Type: array, boolean, null, number, object, string, or undefined

A user-defined item of any type that is returned in the AsyncResult object without being altered. Optional.

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 addFromPromptAsync method, you can use the properties of the AsyncResult object to return the following information.

Property

Use to...

AsyncResult.value

Access the Binding object that represents the selection specified by the user.

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.

Adds a binding object of the specified type to the Bindings collection, which will be identified with the supplied id. The method fails if the specified selection cannot be bound.

function addBindingFromPrompt() {

    Office.context.document.bindings.addFromPromptAsync(Office.BindingType.Text, { id: 'MyBinding', promptText: 'Select text to bind to.' }, function (asyncResult) {
        write('Added new binding with type: ' + asyncResult.value.type + ' and id: ' + asyncResult.value.id);
    });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

Supported clients

Excel 2013, Excel 2013 RT and Excel Online

Library

Office.js

Namespace

Office

Show:
© 2015 Microsoft