Office-js: Office.context.mailbox.item is null in ViewModel "ICalendarItemDetailsViewModelFactory"

Created on 28 Jul 2017  路  8Comments  路  Source: OfficeDev/office-js

Expected Behavior

When opening my add-in in an appointment that is displayed the the view model mentioned in the title, Office.context.mailbox.item should not be null.

Current Behavior

When opening my add-in in an appointment that is displayed the the view model mentioned in the title, Office.context.mailbox.item is always null. I don't mean Office.context.mailbox.item or Office.context.mailbox.item.itemId. Also this is working correctly for messages (e-mails).

Steps to Reproduce

  1. Create an add-in that works inline for calendar items (and mail items, if you wish).
  2. Have the add-in output Office.context.mailbox.item (e.g. via console.log()).
  3. Optional: Compare with the output if you open the add-in inside a message item (e-mail)

Context

Trying to use the add-in to link some data to the item whithin our CRM software. It works fine for e-mails (Office.MailboxEnums.ItemType.Message).
In edit mode the add-in is loaded inside the taskbar and the item is set.

Your Environment

  • Platform [PC desktop, Mac, iOS, Office Online]: Office Online (OWA/Outlook on the web)
  • Host [Excel, Word, PowerPoint, etc.]: Outlook
  • Office version number: Exchange 2016 CU5 / API requirement set 1.5
  • Operating System: Windows 10
  • Browser (if using Office Online): Chromium

Useful logs

  • Console Error: "Uncaught TypeError: Cannot read property 'itemId' of null"
  • Inline add-in:
    image
Outlook

All 8 comments

Adding @annich-MS from the Outlook team.

Hi, are you by chance attempting to get the itemid of an appointment that you are the organizer for? Currently items that you created open in compose mode. Per the documentation here:

The itemId property is not available in compose mode. If an item identifier is required, the saveAsync method can be used to save the item to the store, which will return the item identifier in the AsyncResult.value parameter in the callback function

This means that in add-ins being run on an calendar item that you created, you must get the itemid from saveAsync.

I can not use saveAsync on the item, because the item itself is null. I know that I can not just get the itemId in some cases, that's why my code looks like this:

window.currentItemID = Office.context.mailbox.item.itemId;

if (Office.context.mailbox.item.saveAsync) {
    Office.context.mailbox.item.saveAsync(function (asyncResult) { // HOW TO GET THE ITEM ID
        window.currentItemID = asyncResult.value;
        initialStuff();
    });
} else {
    initialStuff();
}

This will throw the mentioned error: Uncaught TypeError: Cannot read property 'itemId' of null

I'm unable to repro this myself. Is there a way you can give me a gist that repros this?

I've created a simple test project to reproduce this.

Host the test.html on https://localhost/test.html and load the add-in via the manifest (simpleAddin.xml).

  1. Create a new mail and open the add-in (taskpane). It will write the item as [Object, Object] - all good here!
  2. Create a new appointment.
  3. Copy the itemId from the object (the object is logged to console via the add-in).
  4. Open the following URL with your EXCHANGE_SERVER_URL and the copied ITEM_ID:

    https://[EXCHANGE_SERVER_URL]/owa/#ItemID=[ITEM_ID]&exvsurl=1&viewModel=ICalendarItemDetailsViewModelFactory

  5. Open the add-in, it will print out null, as the item is null in this situation.

Test project files:

simpleTestForNullProject.zip

@annich-MS did you manage to reproduce the issue with the provided example (simpleTestForNullProject.zip)?

So no update yet?

It appears that you're attempting to create a deep linking scenario. This scenario is not officially supported in any version of outlook. You can request this feature in our User Voice

Was this page helpful?
0 / 5 - 0 ratings