In my office js app for Word, sometimes a content control looses connection, so I cannot see the content control any longer, and then the document is broken for inserting new content controls of that type. I am not able to delete the broken content control, and I am not able to insert text into the broken content control. The broken content control is not visible in the document, but it exists, since it is not a null object.
Has anybody else encountered this issue?
Is it possible to do anything at all after a content control has been broken? Is it possible to remove it in some manual way? Or remove the entire list of a certain type of content control?
Here is a long example explaining what happens after a broken content control:
const example = context.document.contentControls
.getByTag("example")
.getFirstOrNullObject();
context.sync();
if (!example.isNullObject) {
console.log("Example: ", example);
// This logs meaning that the first object with tag "example" is not a null object,
// so it exists somehow.
// Logs: "Example: n {m_contextBase: n, m_objectPath: t, m_context: n, _IsTracked: true}"
example.insertHtml("Example text in existing content control", Word.InsertLocation.replace);
context.sync();
// This breaks and the rest of the code does not continue.
// But, if I remove this, and we continue anyways this happens:
example.delete(false);
context.sync();
console.log("Deleted"); // This is not logged meaning that it breaks on deleting the content control
}
// What if I insert a new content control of the same type?
const range = context.document.getSelection();
const contentControl = range.insertContentControl();
contentControl.title = "Example";
contentControl.tag = "example;
contentControl.appearance = Word.ContentControlAppearance.boundingBox;
contentControl.insertHtml("Example in new content control", Word.InsertLocation.replace);
contentControl.color = "lightSkyBlue";
await context.sync();
const html = contentControl.getHtml();
await context.sync();
console.log("html", html.value); // This is logged with the correct value