DocumentBuilder icon indicating copy to clipboard operation
DocumentBuilder copied to clipboard

Error when transferring `oTextPr` object via GlobalVariable

Open PaSen-pzk opened this issue 3 years ago • 5 comments

Integrate ONLYOFFICE Document Builder into my application on Node.js. Using globalvariable method to create paragraph object will cause errors. Steps to reproduce the problem: Exception Info:

Uncaught TypeError: Converting circular structure to JSON --> starting at object with constructor 'cb' --- property 'va' closes the circle

Script example:

builder.OpenFile("2022072-10000-81acb5fcd08244e3926c891263cfe168.docx");
var tempDocument = Api.GetDocument();
var tempDocumentParagraphs= tempDocument.GetElement(0);
GlobalVariable[ "CommentsReport" ] = tempDocumentParagraphs;
builder.CloseFile();
builder.OpenFile("2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx");
var curDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
var tempParagraph = global;
oParagraph.InsertParagraph(tempParagraph, "after" , true );
curDocument.Push(oParagraph); 
builder.SaveFile("docx", "Result4.docx");
builder.CloseFile();

Execution mode: Run the above script with the executable file of docbuilder under the onlyoffice installation directory. DocumentBuilder version: Version: 7.1.1 Installation method: Download and unpack on Windows . Operating system: Windows11

PaSen-pzk avatar Jul 14 '22 07:07 PaSen-pzk

Hi, I think we need both those files to correctly diagnose the situation "2022072-10000-81acb5fcd08244e3926c891263cfe168.docx" "2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx"

ShockwaveNN avatar Jul 14 '22 08:07 ShockwaveNN

Hello @PaSen-pzk ! You are not using GlobalVariable correctly.

Example of correct usage:

builder.OpenFile("2022072-10000-81acb5fcd08244e3926c891263cfe168.docx");
var oDocument = Api.GetDocument();
GlobalVariable["CommentsReport"] = oDocument.GetElement(0).GetText();
builder.CloseFile();

builder.OpenFile("2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx");
var oCommentsReport = GlobalVariable["CommentsReport"];
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.InsertParagraph(oCommentsReport, "after", true);
builder.SaveFile("docx", "Result.docx");
builder.CloseFile();

l8556 avatar Jul 14 '22 10:07 l8556

你好@PaSen-pzk! 您没有正确使用 GlobalVariable。

正确用法示例:

builder.OpenFile("2022072-10000-81acb5fcd08244e3926c891263cfe168.docx");
var oDocument = Api.GetDocument();
GlobalVariable["CommentsReport"] = oDocument.GetElement(0).GetText();
builder.CloseFile();

builder.OpenFile("2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx");
var oCommentsReport = GlobalVariable["CommentsReport"];
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.InsertParagraph(oCommentsReport, "after", true);
builder.SaveFile("docx", "Result.docx");
builder.CloseFile();

In this case, there is no guarantee that the merged content format is consistent with the source file. In the way you provided, I tried to get the text format, that is, apitextpr, and add it to the global variable, but the function contained in this apitextpr object cannot be serialized, so it is not available.

PaSen-pzk avatar Jul 15 '22 02:07 PaSen-pzk

你好@PaSen-pzk! 您没有正确使用 GlobalVariable。 正确用法示例:

builder.OpenFile("2022072-10000-81acb5fcd08244e3926c891263cfe168.docx");
var oDocument = Api.GetDocument();
GlobalVariable["CommentsReport"] = oDocument.GetElement(0).GetText();
builder.CloseFile();

builder.OpenFile("2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx");
var oCommentsReport = GlobalVariable["CommentsReport"];
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.InsertParagraph(oCommentsReport, "after", true);
builder.SaveFile("docx", "Result.docx");
builder.CloseFile();

In this case, there is no guarantee that the merged content format is consistent with the source file. In the way you provided, I tried to get the text format, that is, apitextpr, and add it to the global variable, but the function contained in this apitextpr object cannot be serialized, so it is not available.

This is a bug. Issue 58126 in our private issue tracker.

l8556 avatar Jul 15 '22 12:07 l8556