Get Started
Plugins
Macros
More information

window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [args], callback)

Description

Defines the method that allows inserting the content control containing data. The data is specified by the js code for Document Builder, or by a link to the shared document.

Usage

This method should be used in the following way:

window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [arrDocuments]);
Parameters
Parameter Description Type Example
arrDocuments An array of properties and contents of the content control. Each object from this array can have the following values:
  • Props - the content control properties,
    type: object;
  • Script - a script that will be executed to generate the data within the content control (can be replaced with the Url parameter),
    type: string,
    example: "{script}";
  • Url - a link to the shared file (can be replaced with the Script parameter),
    type: string,
    example: "https://example.com/script.docbuilder".
array of objects

The Props object can have the following values:

Parameters
Parameter Description Type Example
Id A unique identifier of the content control. It can be used to search for a certain content control and make reference to it in the code. integer 2
Tag A tag assigned to the content control. The same tag can be assigned to several content controls so that it is possible to make reference to them in the code. string "{tag}"
Lock A value which defines if it is possible to delete and/or edit the content control or not. integer 0
InternalId A unique internal identifier of the content control. string "1_713"
Alias The alias attribute. string "№1"
PlaceHolderText The content control placeholder text. string "placeholder text"
Appearance Defines if the content control is shown as the bounding box (1) or not (2). integer 1
Color The color for the current content control in the RGB format:
  • R - red color component value,
    type: integer,
    example: 0;
  • G - green color component value,
    type: integer,
    example: 0;
  • B - blue color component value,
    type: integer,
    example: 255;
object

The Lock parameter can have the following values:

Numeric value Edit Delete
0 No Yes
1 No No
2 Yes No
3 Yes Yes
Returns

The method returns the data which the created content control contains (in JSON format):

[
    {
        "Tag": "Document",
        "Id": 0,
        "Lock": 0,
        "InternalId": "1_713"
    }
]
Example of changing the existed content control
var arrDocuments = [{
    "Props": {
        "InternalId": "2_803"
    },
    "Script": "var oParagraph = Api.CreateParagraph();oParagraph.AddText('New text');Api.GetDocument().InsertContent([oParagraph]);"
}]
window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [arrDocuments]);
Example of adding a new content control
var arrDocuments = [{
    "Props": {
        "Id": 100,
        "Tag": "CC_Tag",
        "Lock": 3
    },
    "Script": "var oParagraph = Api.CreateParagraph();oParagraph.AddText('Hello world!');Api.GetDocument().InsertContent([oParagraph]);"
}]
window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [arrDocuments]);