Ability to run JS Add In code whenever a document is open

Ability to run JS Add In code whenever a document is open
1

Upvotes

Upvote

 Dec 17 2023
0 Comments 
New

We have an `Office.onReady` function that enables/disables "Login" and "Logout" buttons in the ribbon to match the user's logged in state.

 

When a user opens a new document, the onReady function does not get called until either a custom function is ran or the taskpane is open.

 

There should be initialization function we can call when the custom functions are registered, as according to the runtime logs, they get registered every time a document is opened which is when we would ideally be calling this.

 

See below video, which was taken with a fresh workbook and showcases that both `Office.initialize` and `Office.onReady` aren't called until a function is ran - and then my ribbon updates to the intended state.

 

https://github.com/OfficeDev/office-js/assets/16158417/33070de4-cc3a-444d-a0c6-b2c1cff3016e

 

We would like to show the user's login state, and also disable/enable buttons based on who is logged in. Users will be confused if they are presented with disabled buttons that should be enabled, or with a login button when they have already logged in.