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
670 stars 96 forks source link

Item Id is converted to different format when the pane is opened #4657

Closed riddhi-p-28 closed 3 weeks ago

riddhi-p-28 commented 2 months ago

We are developing an outlook web addin using office js Smart alert template. We are utilizing itemID for our validation process to segregate the sessions of different mail compose windows in our web add-in. Due to the above issue, our validation results for different compose windows are getting jumbled up. We observed that item ID is being changed when we switch from one compose window to other compose window and come back. When we switch from the window the itemID is being changed to "clientId: {{GUID}}' format instead of base64 format in some cases. 316de29d-5143-48b3-af79-4506a9ac318c

4b07d614-20a7-4a7f-8b68-7c521937052d

Your Environment

Steps to reproduce

  1. Open outlook desktop app.
  2. Compose a new email
  3. Add recpients , subject and body and attachments
  4. Observe the Item id in local storage
  5. Click on send or mailtip
  6. Observe the item id in local storage

Expected behavior

The itemID should not be converted to 'clientId: {{GUID}}' format.

Current behavior

In step 4 the item id is shown in the format "clientId: {{GUID}}' In step 6 the item id is in Base64 format. Because of this attachments are not getting displayed in the side pane

neprasad-microsoft commented 2 months ago

Hi @riddhi-p-28 How are you getting the itemID in local storage? Which API are you using for this?

riddhi-p-28 commented 1 month ago

We are using below API to get the ITEMID and storing the same in localstorage:

Office.context.mailbox.item.saveAsync((result) => { if (result.status === Office.AsyncResultStatus.Succeeded) { // store in localstorage localStorage.setItem("ITEMID", result.value); } else { console.log("Error saving item ID"); } });

cody-lettau commented 1 month ago

We reproduce this in the following fashion:

Steps to reproduce

  1. Compose a new message and open the add-in
  2. Call Office.context.mailbox.item.getItemIdAsync and note the message id returned (looks something like clientid:{{guid}}
  3. Close the add-in.
  4. Open the add-in and call Office.context.mailbox.item.getItemIdAsync again and note the new message id that is returned (looks more like what we'd expect -- ex: AAMkAGRjNjgzMzFkLTk4NDAtNDNhNC1iN2IwLTRlZDlkOTc5MDA2OQBGAAAAAACBRef0LyuDT6qtuGLHHQMtBwBUwWi/zK7oTKigK60c9jLNAAAAAAEPAABUwWi/zK7oTKigK60c9jLNAAGVU4hQAAA=)

We have the following function that we call to get the id:

export const saveItem = (includeId) => new Promise((resolve, reject) => {
    try {
        Office.context.mailbox.item.saveAsync((saveResult) => {
            if (saveResult.status !== Constants.getAsyncResultSuccessStatus()) {
                console.error('Error saving mailbox item: ', saveResult.error);
                reject(new Error('Error saving mailbox item'));
                return;
            }

            if (!includeId) {
                resolve(saveResult.value);
                return;
            }

            Office.context.mailbox.item.getItemIdAsync(getItemResult => {
                if (getItemResult.status !== Constants.getAsyncResultSuccessStatus()) {
                    console.error('Error getting id for saved mailbox item (during save): ', getItemResult.error);
                    reject(new Error('Error getting id for saved mailbox item'));
                    return;
                }

                resolve(getItemResult.value);
            });
        });
    } catch (e) {
        console.log('Error saving mailbox item: ', e);
        reject(e);
    }
});

We found that if we call this twice, with a slight delay between the calls, we end up getting back what is expected (delay we have set is 250ms).

kumarshrey-msft commented 3 weeks ago

This issue has been fixed. Thank you for raising the issue and helping us make the product better.