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
689 stars 95 forks source link

Code works when called from Task Pane but not when called from Function #5042

Open matthewfitzmaurice opened 2 weeks ago

matthewfitzmaurice commented 2 weeks ago

Code works when called from Task Pane but not when called from Function

Environment

Expected behavior

I expect code to produce the same results whether run from a Task Pane or a Function.

Current behavior

The example code listed in the Field.UpdateResult documentation works when run in a Task Pane. The code does NOT work when run from a Ribbon Button function. https://learn.microsoft.com/en-us/javascript/api/word/word.field?view=word-js-preview#word-word-field-updateresult-member(1)

Steps to reproduce

  1. Create a blank document
  2. Insert some text
  3. Insert a NumWords field
  4. Insert some more text
  5. Run the sample Microsoft Field.UpdateResult code from either a Task Pane button or a Function button
RuizhiSunMS commented 2 weeks ago

hi @matthewfitzmaurice, thx for your submit. May I confirm that, the meaning of 'ribbon button function' is creating a ribbon addin, which contains one button to execute that example code function?

matthewfitzmaurice commented 2 weeks ago

Yes. It is also possible to create an office add-in with a manifest that contains 2 buttons on the ribbon. One button creates a task pane whereas the other just calls a function.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: RuizhiSunMS @.> Sent: Tuesday, November 5, 2024 7:49:31 PM To: OfficeDev/office-js @.> Cc: Matthew Fitzmaurice @.>; Mention @.> Subject: Re: [OfficeDev/office-js] Code works when called from Task Pane but not when called from Function (Issue #5042)

hi @matthewfitzmauricehttps://github.com/matthewfitzmaurice, thx for your submit. May I confirm that, the meaning of 'ribbon button function' is creating a ribbon addin, which contains one button to execute that example code function?

— Reply to this email directly, view it on GitHubhttps://github.com/OfficeDev/office-js/issues/5042#issuecomment-2456962026, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA4DOOTU6FX3VPMFSWEI3KLZ7CWEXAVCNFSM6AAAAABRGH3MU2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINJWHE3DEMBSGY. You are receiving this because you were mentioned.Message ID: @.***>

RuizhiSunMS commented 2 weeks ago

hi @matthewfitzmaurice , would you please share your files with us? It could be helpful to accelerate our investigation.

matthewfitzmaurice commented 2 weeks ago

TemplaBee.Office.js.NAA - Sample.zip

Please unzip this attachment. The ribbon contains a custom tab with two buttons on it. You will see that the buttons are labelled 'Refresh Links (works)' and 'Refresh Links (Does NOT work)'.

Test scenario:

  1. Enter some text into a document.
  2. Add a NumWords field.
  3. Enter some more text into the document.
  4. Select the field and press the 'Refresh Links (Does NOT work)' button. The button should cause the NumWords field to update.
  5. Select the field and press the 'Refresh Links (works)' button. A task pane will open. Press the 'Update Field result' button. The NumWords field will correctly update.
RuizhiSunMS commented 2 weeks ago

Create work item #9509954 to track it, the team will investigate and we will reply to you as soon as there is any progress. Thank you for your patience.