Automation API

Connector is a class that allows editing text documents, spreadsheets, presentations, and fillable forms from an external source. The examples of using Automation API can be found here.

To create the connector, use the createConnector method of the document editor object:

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
    Name Description Type
    name The event name. string
    callback The event listener. function
    Example
    connector.attachEvent("onChangeContentControl", function()
    {
        console.log("event: onChangeContentControl");
    });
    
  • 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
    Name Description Type
    command Defines 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
    callback The result that the method returns. It is an optional parameter. function
    isNoCalc Defines 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
    Asc.scope.text = "Hello world!"; 
    
    connector.callCommand(function() {
    
        var oDocument = Api.GetDocument();
        var oParagraph = Api.CreateParagraph();
        oParagraph.AddText(Asc.scope.text);
        oDocument.InsertContent([oParagraph]);
    
    }, 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
    connector.connect()
    
  • detachEvent - the function called to remove an event listener.

    Parameters
    Name Description Type
    name The event name. string
    Example
    connector.detachEvent("onChangeContentControl");
    
  • disconnect - the function called to disconnect the connector from the editor.

    Example
    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
    Name Description Type
    name The name of the specific method that must be executed. string
    args The arguments that the method in use has (if it has any). array
    callback The result that the method returns. It is an optional parameter. function
    Example
    connector.executeMethod("SetFormValue",[forms[i]["InternalId"],"OnlyOffice BANK"],null);