document.body.clear() fails with exceptions on Word Online Script Lab
Closed this issue · 4 comments
Script Lab fails to clear document body on Word Online --
Script Lab public gist link
https://gist.github.com/kenual/31548c30cfb12004177af89d44effbe0
The same script works fine inside Script Lab on Word 365 Win32 Version 1706
Expected Behavior
After base64 file is inserted, context.document.body.clear() should succeed on Word Online just like Word on Windows.
Current Behavior
Script Lab shows Office JS exceptions running on Word Online
context.document.body.clear() should work on Word Online like it does on Word.
Steps to Reproduce, or Live Example
- Link to live example: ______
Open Script Lab on Word Online
Open Basic API call (Javascript) sample
Copy github public gist
https://gist.github.com/kenual/31548c30cfb12004177af89d44effbe0
and paste into Script Lab Script
Click Run button to execute the Word JS block
- Additional details:
-
Context
Our Add-in's primary users are on Word Online. This bug is causing our Add-in not able to update the document with updated file content. The same API call and functionality works fine on Word.
Your Environment
- Platform [PC desktop, Mac, iOS, Office Online]: Office Online
- Host [Excel, Word, PowerPoint, etc.]: Word
- Office version number: Version 1706
- Operating System: Windows
- Browser (if using Office Online): Chrome
Useful logs
- Console errors
- Screenshots
- Test file (if only happens on a particular file)
something with the content of this document is what makes it fail. we are investigating the issue. sorry for the insane delay!
Have narrowed down the steps to reproduce this issue. It only happens when the document body has only one single paragraph which contains the unsupported features such as field and/or unsupported content controls. This is a bug, and we are working on a fix.
However, the above script actually fails at the step when you try to insert content control to the range which is the inserted base64 stream that contains a field. It fails because field is not supported in Word Online, and therefore we disallow insert content control on the range.
team is working on a fix, been tracked with 2452427 internally.
I had the similar trouble. The following code worked for me:
Word.run(async (context) => { let range = context.document.getSelection(); let pageRange = range.parentBody.getRange(); pageRange.delete(); await context.sync(); })