Content Control - How to insert html in content control while creating from plugin

let _obj = {“commonPr” :{“Id” : 1,“Tag” : “{Document1}”,“Lock” : 3,“Appearance” : 2},“type”:1}

let getHTMLContent = "




1. Testing For SME Required inClause Type

    <div class="clause-content" style="margin-left: 20px;">
      <p>Testing For SME Required inClause Type</p>
    </div>
      </div></div>";

  window.Asc.plugin.executeMethod("AddContentControl", [_obj.type, _obj.commonPr],() => {       
    window.Asc.plugin.executeMethod(
      "GetAllContentControls",
      [],
      (returnValue) => {
        returnValue
          .forEach((control) => {
            if(control.Id ===1){
              const id = control.InternalId;
              //const key = control.Tag.slice(tagPrefix.length)
              //const value = values[key]                 
                window.Asc.plugin.executeMethod(
                  "SelectContentControl",
                  [id],
                  () => {
                  window.Asc.plugin.executeMethod("PasteHtml", [getHTMLContent], (data)=>{
                      console.log(data)
                    })
                  }
                )
            }                
          })
  });
})

I have tried to execute below code in the screnshot.but nothing happens ,document got freezed. No error in the console.

.

Please provide an working example to insert html in content control.

Hello @bala,

On your screenshot, the lock is set to 0 which means the Content Control cannot be edited.

You can insert an empty CC with AddContentControl and then execute PasteHTML in the callback of this method to paste the HTML content inside this empty CC:

window.Asc.plugin.executeMethod ("AddContentControl", [1, {"Id" : 7, "Tag" : "{tag}", "Lock" : 3}], function (pastehtml) {window.Asc.plugin.executeMethod ("PasteHtml", ["<p><b>Plugin methods for OLE objects</b></p><ul><li>AddOleObject</li><li>EditOleObject</li></ul>"])});

Hi @Carl,
Thanks for the reply.
How to position the cursor/caret to end of Content Control after inserting . Because we have scenario to insert multiple content control one after other, So need help here.

Hello @bala,

I see that your colleague is posting the same requests in our Helpdesk. Please do not duplicate your requests in several communication channels.
Moving cursor outside a CC is possible with this method
https://api.onlyoffice.com/docs/office-api/usage-api/text-document-api/apiblocklvlsdt/movecursoroutside/