How to add disable AddContentControl in docx?

I’m trying to create a plugin where it inserts the html content in docx and it needs to be disabled. also, there will be clear option in plugin which will clear the inserted content in docx. How can i achieve this??

I’ve used AddContentControl and added the html but its editable. with disabled AddContentControl, i can’t add html content on it and can’t remove it as well.
Here’s my code:

window.Asc.plugin.executeMethod("AddContentControl", [
          1,
          { Id: 1, Tag: "documentVersions", Lock: 0 },
        ]);
        window.Asc.plugin.executeMethod("MoveCursorToContentControl", [
          1,
          true,
        ]);
        window.Asc.plugin.executeMethod("PasteHtml", [text]);

Hello @anand.mainali

Let’s start from the scenario that you are trying to achieve. I’m failing to understand the purpose of using AddContentControl in this approach when you can simply insert your HTML code with PasteHtml method.

Please share step-by-step scenario on your goal.

@Constantine yes i’ve inserted my html code in docx using PasteHtml & AddContentControl method… but i also want to lock that ContentControl and can be only deleted.

My goal is to insert the html content and prevent users from editing that content… but that content can be updated by system by removing the existing and adding new one.

I see. Important to understand that adding content control with lock 0 already does not allow inserting any content inside, hence you need to add content control and lock it after pasting HTML code.
However, PasteHtml method takes some time to execute and attempting to lock content control right after that may result in empty content control.

I’ve came up with such solution:

(function (window, undefined) {
    window.Asc.plugin.init = function () {
        var text = "<p>Some text</p>"
        window.Asc.plugin.executeMethod("AddContentControl", [1, { "Id": 1, "Tag": "documentVersions", "Lock": 3 }]); // Adds unlocked content control
        window.Asc.plugin.executeMethod("PasteHtml", [text]); // Pastes HTML

        window.Asc.plugin.onMethodReturn = function () { // Once previous PasteHtml method has finished, sets up a lock on inserted content control
            if (window.Asc.plugin.info.methodName == "PasteHtml") {
                window.Asc.plugin.callCommand(function () {
                    var oDocument = Api.GetDocument();
                    var aContentControls = oDocument.GetContentControlsByTag("documentVersions");
                    console.log(aContentControls);
                    aContentControls[0].SetLock("sdtContentLocked"); // Full lock
                })
            } else if (console.log("Abort"));
        };
    }
})(window, undefined);

As you can see, I’ve omitted MoveCursorToContentControl method as right after executing AddContentControl the content control itself stays in focus.

Methods used: onMethodReturn, callCommand, GetContentControlsByTag, SetLock.