Search code examples
outlookoffice365outlook-addinoffice-addins

Error in Office Outlook Add-in during Initiallzation


I get an error as this when loading my Outlook add-in in the Desktop client:

SCRIPT5022: Office.js has not been fully loaded yet. Please try again later or make sure to add your initialization code on the Office.initialize function.

My initialization code looks something like this:

Office.initialize = function (reason) {
    app.initialize();

    // set adal.js b2c authentication
    setAuthContext();

    // handle any window callback redirections
    authContext.handleWindowCallback();

    checkUser();
    setListeners();
};

I tried different variations with the initialize function of Office.js but I get the same error over and over again. This doesn't happen with the same outlook add-in in Outlook online.

Am I doing something wrong with the Office app initialization?


Solution

  • I think you need to use $(document).ready or window.onload and then set your code.

    From the documentation:

    If you are using additional JavaScript frameworks that include their own initialization handler or tests, these should be placed within the Office.initialize event. For example, JQuery's $(document).ready()

    code:

    Office.initialize = function () {
    // Office is ready
    $(document).ready(function () {        
        // The document is ready insert your code here
    
    });
    };