Automation API

Connector is a class that allows interaction with text documents, spreadsheets, presentations, and fillable forms from the outside. To create the connector, use the createConnector method of the document editor object:

  1. var connector = docEditor.createConnector()

Please note that the connector is available only for ONLYOFFICE Developer Edition.

This class is an additional feature which is available at extra cost. If you have any questions, please contact our sales team at sales@onlyoffice.com.

The connector has the same interface as plugins. Below you can find methods that are available for this class.

Methods and their description:

  • attachEvent - the function called to add an event listener, a function that will be called whenever the specified event is delivered to the target. The list of all the available events is the same as for the plugins. It can be found here.

    Parameters

    NameDescriptionType
    nameThe event name.string
    callbackThe event listener.function

    Example

    1. connector.attachEvent("onChangeContentControl", function()
    2. {
    3. console.log("event: onChangeContentControl");
    4. });
  • callCommand - the function called to send the data back to the editor. It allows the connector to send structured data that can be inserted into the resulting document file (formatted paragraphs, tables, text parts, and separate words, etc.).

    ONLYOFFICE Document Builder commands can be only used to create content and insert it into the document editor (using the Api.GetDocument().InsertContent(…)). This limitation exists due to the co-editing feature in the online editors.

    Parameters

    NameDescriptionType
    commandDefines the command written in JavaScript which purpose is to form structured data which can be inserted into the resulting document file (formatted paragraphs, tables, text parts, and separate words, etc.). Then the data is sent to the editors. The command must be compatible with ONLYOFFICE Document Builder syntax.function
    callbackThe result that the method returns. It is an optional parameter.function
    isNoCalcDefines whether the document will be recalculated or not. The true value is used to recalculate the document after executing the function in the command parameter. The false value will not recalculate the document (use it only when your edits surely will not require document recalculation). The default value is false.boolean

    This method is executed in its context isolated from other JavaScript data. If some parameters or other data need to be passed to this method, use Asc.scope object.

    Example

    1. Asc.scope.text = "Hello world!";
    2. connector.callCommand(function() {
    3. var oDocument = Api.GetDocument();
    4. var oParagraph = Api.CreateParagraph();
    5. oParagraph.AddText(Asc.scope.text);
    6. oDocument.InsertContent([oParagraph]);
    7. }, function() { console.log("callback command"); });
  • connect - the function called to connect the connector to the editor.

    Please note that this method should only be called if you have disconnected the connector with the disconnect method and need to connect it to the editor again. When creating a connector, you do not need to use the connect method, as it is called automatically along with the createConnector method.

    Example

    1. connector.connect()
  • detachEvent - the function called to remove an event listener.

    Parameters

    NameDescriptionType
    nameThe event name.string

    Example

    1. connector.detachEvent("onChangeContentControl");
  • disconnect - the function called to disconnect the connector from the editor.

    Example

    1. connector.disconnect()
  • executeMethod - the function called to execute certain editor methods using the connector. The full list of these methods is the same as for the plugins. It can be found here.

    Parameters

    NameDescriptionType
    nameThe name of the specific method that must be executed.string
    argsThe arguments that the method in use has (if it has any).array
    callbackThe result that the method returns. It is an optional parameter.function

    Example

    1. connector.executeMethod("SetFormValue",[forms[i]["InternalId"],"OnlyOffice BANK"],null);