OfficeDev / office-js-docs-pr

Microsoft Office Add-ins Documentation
https://learn.microsoft.com/office/dev/add-ins
Creative Commons Attribution 4.0 International
407 stars 250 forks source link

Issue when trying to unregister an event following the documentation examples #4909

Open frankybboy96 opened 1 week ago

frankybboy96 commented 1 week ago

Article URL

https://learn.microsoft.com/en-us/office/dev/add-ins/word/word-add-ins-events#remove-an-event-handler

Issue

The documentation gives instructions on how to register and then unregister events, but the provided code example isn't valid and doesn't work even in the most basic sense.

the eventContext.context provided as a param in the Word.run has a type mismatch and is not working. image

trying to work around the issue by casting doesn't resolve the issue and just leads to the Word.run to throw image image

also the example provided doesn't take into account the possibility that eventContext could potentially be undefined or null, which is also wrong but easily fixed by adding some if(eventContext) where needed.

Questions

Is there another approved way of registering/unregistering events that I haven't found in the documentation?

Is there other ways to get notified of document changes that do not rely on the events?

frankybboy96 commented 5 days ago

When can I expect to get any news relating to this?

Rick-Kirkham commented 5 days ago

@frankybboy96 This is a holiday week in the USA. @ElizabethSamuel-MSFT will be back next week. I the meantime, please install the ScriptLab tool from AppSource and try the sample in this screen shot. The code is similar to what is in the article. It will be valuable to see if the sample works in Script Lab or gives you and error. (It works perfectly for me.) image

microsoft-github-policy-service[bot] commented 1 day ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!