Get Started
Plugins
Macros
More information

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

Description

Defines the method that allows inserting a 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 A JSON array of properties and contents for content controls. 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 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:

  • Id (e.g. {"Id": 2} ) is 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.
  • Tag ( e.g. {"Tag": "{tag}"} ) is 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.
  • InternalId (e.g. {"InternalId": 1_713} ) is a unique internal identifier of the content control.
  • Lock (e.g. {"Lock": 0} ) is a value which defines if it is possible to delete and/or edit the content control or not. The values can be as follows:
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]);