Reputation: 4341
I have an issue with content controls. There is 5 CCs in body itself, and 3 CCs inside a table inside the body.
This sample code just returns 5 CCs directly inside document body. I've ensured that all CCs are type of rich text content control.
Word.run(function (context) {
const { document, document { body } } = context.document;
context.load(document, 'contentControls');
//Or context.load(body, 'contentControls');
return context.sync().then(function () {
const { contentControls } = document;
//Or const { contentControls } = body;
console.warn("len", contentControls.items.length);
});
}).catch(function (e) {
console.error(e);
});
Upvotes: 0
Views: 211
Reputation: 13500
I'm unable to reproduce the issue that you describe. First, I completed the following setup steps:
Here's what that content looks like in the document:
After manually creating the document and adding content as described above, I ran this code snippet.
Word.run(function (context) {
var myContentControls = context.document.contentControls;
myContentControls.load("tag");
return context.sync()
.then(function () {
for (var i = 0; i < myContentControls.items.length; i++)
{
myContentControls.items[i].color = "blue";
myContentControls.items[i].title = "myCC";
myContentControls.items[i].appearance = "tags";
}
return context.sync();
});
}).catch(OfficeHelpers.Utilities.log);
This code snippet gets the content controls that the document contains and then sets tag properties for each one. As you can see from the following screenshot (which shows the document after the code snippet runs), all 3 content controls are successfully being identified, including the one that's inside the table.
Upvotes: 2