How to use builder object in plugins?

How to use builder object in plugins?
I want to use a plugin to insert the contents of other files into the currently open document.
So, I write code below and get an error.

builder.OpenFile("http://ip:port/example/download?fileName=new.docx");
var oDocument = Api.GetDocument();
var oContent = oDocument.GetContent();
GlobalVariable["1"] = oContent
builder.CloseFile();

// in editor, The opened file you want to insert content into
var text = GlobalVariable["1"];
var oDoc = Api.GetDocument();
var oP = oDoc.GetElement(0);
oP.AddText("Data from other file: " + text);

Document Server version: 7.4.1
Installation method: docker
OS: centos7
Browser version: chrome lastest

Hello @tankxxl

Unfortunately, builder class is exclusively available for Document Builder when used in .docbuilder scripts and cannot be used in plugins. Check this article about usage of docbuilder scripts: https://api.onlyoffice.com/docbuilder/integrationapi/usingdocbuilderfile

In general, I’d ask you to provide more details about the plugin you are developing. Main question here is where the source file from which content you want to copy is located? In the same storage or somewhere else?
Also, specify step-by-step scenario of what you want your plugin to perform.

Thanks.
Firstly, somewhere on the internet (URL), I have some Word documents.
The user opens the main document and opens the plugin interface I wrote. By clicking the button, the remote Word document content is inserted into the currently open document.
I open the document, not only to edit it, but more importantly, to merge the existing Word document content into the current file.

Thanks.
Firstly, somewhere on the internet (URL), I have some Word documents.
The user opens the main document and opens the plugin interface I wrote. By clicking the button, the remote Word document content is inserted into the currently open document.
I open the document, not only to edit it, but more importantly, to merge the existing Word document content into the current file.

In general, for this scenario you can use Content Controls. If your source document has all text inside a rich-text Content Control, you can fetch content from it and paste to the current document with method InsertAndReplaceContentControls.

You can also download an install this test plugin that utilizes the same functionality that you are looking for to check out how this method is implemented:
https://github.com/ONLYOFFICE/sdkjs-plugins/tree/master/example_insert_content_and_document

Is there a way to append multiple documents to a content control? I have multiple URLs and I want to insert them one after the other dynamically in the same content control

Hello @fr3fou

Please check out this example plugin:
https://github.com/ONLYOFFICE/sdkjs-plugins/tree/develop/example_work_with_content_controls_content
This one shows how to paste content of one Content Control to another.

See How to use section before running the plugin.

Hello, thanks for the reply.
I’ve looked at that example before (and this one).

I’d like to know how to insert multiple document Urls into one content control.
Let’s take this example:

I have a “root” document, it has some text like this

I’d like to add 3 documents, one after the other, right where the content control is. The documents are hosted on 3 different URLs.

I can use the InsertAndReplaceContentControls method to insert 1 document, like so:

Asc.plugin.executeMethod("InsertAndReplaceContentControls", [
  {
    Props: {
        InternalId: "..."
    },
    Url: "https://personal.onlyoffice.com/products/files/httphandlers/filehandler.ashx?action=view&fileid=4356181&version=0&doc=SUp1RjRQbFVOeExxTE9PZ1RwRUxMcWhpajZJL0MyblB6dU9lbEFaZmNCND0_NDM1NjE4MQ",
    Format: "docx",
  },
]);

This however won’t work if I want to append another document right after it. Calling InsertAndReplaceContentControls on the same InternalId will overwrite the content control’s content with the new document.

Please also check this sample plugin:
https://github.com/ONLYOFFICE/sdkjs-plugins/tree/master/example_work_with_content_controls_tags
Similar to the button in this plugin you can paste content of needed Content Controls to the specific one by tag.

Hello,

I don’t have the content of the remote documents in the user’s clipboard. I only have the URLs. Pasting the text inside the content controls won’t solve this problem.

Hello @fr3fou
Please do not post similar questions in the different threads. As far as I understand, you are checking the possibility of appending content control to another one: Append content at the end of a Content Control
We are checking mentioned scenario, I’m closing this thread as duplicate.