Skip to content

Word.List.paragraphs.items includes paragraphs from ALL lists of the document, rather than just from the list reference #6602

@Metab0i

Description

@Metab0i

Environment

  • Platform: PC
  • Host: Word
  • Word version number: Microsoft® Word for Microsoft 365 MSO (Version 2602 Build 16.0.19725.20126) 64-bit
  • Operating System: Win 11 Version 10.0.26200 Build 26200

Expected behavior

Word.List.paragraphs.items should only include paragraphs that are members of the list, not entire document.

Current behavior

Word.List.paragraphs.items retrieves paragraphs from ALL lists of the document.

Reproduction:

3 Content Controls (CCRef1-3) with 1 list per CC
Image

Javascript:

Office.onReady(async (info) => {
  if (info.host !== Office.HostType.Word) return console.error("Wrong Host Enviornment. Expected Microsoft Word.");

  document.querySelector("button").addEventListener("click", async function (evnt) {
    await Word.run(async (documentContext) => {
      // Get all Content controls of the doc
      const allCCs = documentContext.document.contentControls.load("items, tag, lists");

      await documentContext.sync();

      // Load items on list of each CC
      for (const cc of allCCs.items) {
        cc.lists.load("items");
      }

      await documentContext.sync();

      // Count How many Lists and How many paragraphs in each list
      for (const cc of allCCs.items) {
        console.log(`${cc.tag} - List Amount in CC: ${cc.lists.items.length}`);

        const ccList = cc.lists.getFirstOrNullObject();
        ccList.load("isNullObject, paragraphs, paragraphs/items");

        await documentContext.sync();

        if (ccList.isNullObject) throw new Error("No List found!");

        console.log(`"${cc.tag}" 's List Paragraphs Length: ${ccList.paragraphs.items.length}`);
      }
    });
  });
});

HTML:

...
<div>
	<button type="button">How Many Items?</button>
</div>
...

Result:

Image

Metadata

Metadata

Labels

Area: WordIssue related to Word add-insNeeds: attention 👋Waiting on Microsoft to provide feedback

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions