OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
679 stars 95 forks source link

[WordApi] range.insertField() throws "Sorry, this function isn't available." #4854

Open adomasven opened 1 month ago

adomasven commented 1 month ago

Word Online

Testing a development extension, attempting to insert a field.

        await Word.run(async (context) => {
            const range = context.document.getSelection().getRange();
            range.insertField('Replace', 'Addin');
            await context.sync();
            // Throws RichApi.Error: Sorry, this function isn't available.
            // Perform a runtime check on the Office add-in to find out whether
            // the feature is supported by the host.
        });
adomasven commented 1 month ago

manifest.xml requirement set should be sufficient and worked with the below before.

  <Requirements>
    <Sets DefaultMinVersion="1.1">
      <Set Name="WordApi" MinVersion="1.5"/>
    </Sets>
  </Requirements> 
shanshanzheng-dev commented 1 month ago

Hi @adomasven Thanks for reporting this issue, we'll take a look and report back if we have a suggestion for you.

shanshanzheng-dev commented 1 month ago

Hi @adomasven About the usage of this API, you can check this reference: https://learn.microsoft.com/en-us/javascript/api/word/word.range?view=word-js-preview#word-word-range-insertfield-member(1) Let me know if you still hit the error. If yes, could you share us your manifest? Thanks.

adomasven commented 1 month ago

https://github.com/zotero/zotero-word-js-integration/blob/main/manifest.xml

For the record I have been using the same manifest for the since last year to develop this plugin and inserting fields worked fine before. After reporting some bugs and receiving a response about them being fixed, I returned back to our code to test and found that it now fails with this error.

shanshanzheng-dev commented 1 month ago

Hi @adomasven Thanks for the detail, we'll take a look and report back if we have a suggestion for you.

xiruatms commented 1 month ago

@adomasven , thanks for reporting this. But unfortunately, I can't repro it. Can you help to share with us some screenshot, record or anything more? Can you repro this with ScriptLab?

adomasven commented 1 month ago

Here's the screencast of the error. I pushed some commits to our repository that include the function ran in the video.

https://github.com/user-attachments/assets/c1cf641a-8303-451d-ba31-798f2412f058

xiruatms commented 1 month ago

@adomasven , thanks for the details.

I have taken a try with your steps, it works as the screenshot shown: image

May I know? 1) Did this work before? 2) What's the account you used to access the onedrive please? From the screencast, it seems the icon of "Sign in" was shown.

adomasven commented 1 month ago
  1. Did this work before?

Yes. I last tested this code in April 2024 and it worked.

  1. What's the account you used to access the onedrive please? From the screencast, it seems the icon of "Sign in" was shown.

It's my personal account. I recorded a screencast with a new Chrome profile to make sure anything in my main browser profile like extensions are not interfering. That profile is not signed in into my onedrive account, but the behaviour is the same if it is. I also just tested on Edge and it also doesn't work. The OS is Ubuntu Linux.

I also just tested in new documents and the behavior is the same.

adomasven commented 1 month ago

Any ideas on how to troubleshoot this further?

xiruatms commented 1 month ago

@adomasven , can you take a try with another account? And/or other documents?

adomasven commented 1 month ago

I created a new account and discovered that it works correctly. Why would my account not work? Is there some preference that I can change to fix this? Can I contact someone privately with my account information?

adomasven commented 1 month ago

@xiruatms any ideas on how to amend my primary account or what's caused this? We wouldn't want this to happen in production either.

xiruatms commented 1 month ago

@adomasven , I'm now trying to contact different teams on addressing your issue. Will get back to you if I got any updates. Thanks for your patience.