Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
getAncestorOrNullObject() function return undefined in Microsoft Office Word Api

I am trying to use getAncestorOrNullObject() function to fetch parent section and parent article of selected paragraph in Word document with Microsoft Office Word Add-in in MS Word 365, The issue I'm facing is even if the paragraph's having ancestor still it's returning undefined or null. Here, I've attached sample code and word document i have used, below. So please verify!

  async getAncestor() {
    Word.run(async (context: any) => {
      let range = context.document.getSelection().paragraphs;
      context.load(range, 'text,items,font');
      await context.sync();
      let getAncestorId = range.items[0]?.listItem.getAncestorOrNullObject();
      context.load(getAncestorId, 'text');
      await context.sync();
      context.load(getAncestorId.contentControls, 'items');
      await context.sync();
    });
  }

Any suggestion and solution would be helpful.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!