Export (0) Print
Expand All

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

JavaScript API for Office v1.1

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

Last modified: June 12, 2014

Introduced in Office.js version

1.0

Updated in Office.js version

1.1

Available in requirement sets

Not in a set

_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.

sampleData

Type: TableData

Specifies a table of sample data displayed in the prompt UI as an example of the kinds of fields (columns) that can be bound by your app. The headers provided in the TableData object specify the labels used in the field selection UI. Optional.

Note: This parameter is used only in apps for Access. It is ignored if provided when calling the method in an app for Excel.

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.

  • In apps for Access, you can create table bindings.

  • In apps for Excel, you can create a table binding (passing bindingType as Office.BindingType.Table) for a range of cells that contains tabular data even when that data was not added to the spreadsheet as a table (by using the Insert > Tables >Table or Home > Styles > Format as Table commands).

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

App types

Content apps, Task pane apps

Supported clients

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

Library

Office.js

Namespace

Office

Show:
© 2014 Microsoft