Mac outlook client - Office365 add-in - Pinning - Office.initialize is not calling back

183 Views Asked by At

I am working on developing simple outlook add-in with pinning support. The add-in works fine in windows outlook, chrome and IE. But when we try it in mac outlook client the behaviour is completely different.

  1. Create a add-in with pinning support.

  2. Open up the add-in and pin it.

  3. Change emails

  4. Switch from inbox to sent items and immediately click on another email.

Now If we observe closely the Office.initialize call back will not called back.

Please use following code for debugging.

var isInitialized = false;
Office.initialize = function(reason) {
    console.log('Office initialize callback is getting fired from outlook');
    document.getElementById('status').innerHTML = 'Office is loaded 1';
    isInitialized = true;
};
var attempt = 0; 
var checkOfficeIsInitialized = function() {
    console.log('checking office', attempt);
    setTimeout(function() {
        console.log('is window intialized', isInitialized);
        if (!isInitialized && attempt < 45) {
            attempt++;
            checkOfficeIsInitialized();
        } else {
            if (!isInitialized) {
                document.getElementById('status').innerHTML = 'Failed to initialize outlook';
            } else {
                document.getElementById('status').innerHTML = 'Office is loaded 2';
            }
        }
    }, 1000);
}
checkOfficeIsInitialized();

Here is the html

<!doctype html>
<html>
    <head>
        <title>Tetsing</title>
    </head>
    <body>
        <h3 id="status">Loading....</h3>
        <script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js" type="text/javascript"></script>
        <script src="js/public-login-v2.js" type="text/javascript"></script>
    </body>
</html>
2

There are 2 best solutions below

1
On

Office.initialize callback will run only once when the add-in opens. After pinning the add-in, the callback is not supposed to be called every time when switching between messages. However, you can register ItemChanged event through addHandlerAsync to get update when message changes. Please find more details here.

0
On

This was a bug that we fixed recently. Switching between folders should no longer cause the add-in to re-initialize. If you have opted in for the Insider Fast builds, you should have this fix already. If not, the fix would be rolled out in some time.