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

Description

This method inserts a content control that contains data. The data is specified by the js code for Document Builder, or by the link to a shared document.

Usage

This method should be used in the following way:

window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [obj]);

Where obj is a JSON array:

[
    {
        "Props": {
            "Id": Number,
            "Tag": "{String}",
            "Lock": Number 
        },
        "Script": "var oDocument = Api.GetDocument();var oParagraph = Api.CreateParagraph();oParagraph.AddText('Hello world!');oDocument.InsertContent([oParagraph]);" 
    }
]

Each new element in the array will create a new content control.

[ {"Props": {...}, "Url": "http://"}, {"Props": {...}, "Url": "http://."}, {...}, {...}]

The Props key has the values that can be the following:

  • "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 your code.
  • "Tag" ( e.g. {"Tag": "String"} ) is a tag assigned to the content control. One and the same tag can be assigned to several content controls so that you can make reference to them in your code.
  • "Lock" (e.g. {"Lock": 0} ) is a value that defines if it is possible to delete and/or edit the content control or not. The values can be the following:
Numeric value Edit Delete
0 No Yes
1 No No
2 Yes No
3 Yes Yes

Besides the Props key, there must be a Key/Value pair containing the Url or Script key, that defines the data that will be contained in the content control. If the Url key is used, its value must be a link to a shared file. If the Script key is used, its value must be a script that will be executed to generate the data within the content control.

Example 1
{
    "Url": "https://example.com/script.docbuilder"
}
Example 2
"Script": "var oDocument = Api.GetDocument();
var oParagraph=Api.CreateParagraph();
oParagraph.AddText('Helloworld!');
oDocument.InsertContent([oParagraph]);"
Returns

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

[
    {
        "Tag": "Document",
        "Id": 0,
        "Lock": 0,
        "InternalId": "1_713"
    }
]