Search code examples
office-jsoffice-addinsexcel-addinsword-addins

Office Add-in: Saving Custom Document Properties with Office js in Windows


Background:

I'm developing an add-in in macOS and I am able to read a custom document property:

return await this.api.run(async (context) => {
    const properties = context.document.properties.customProperties;
    properties.load('key,type,value');
    await context.sync();

    const roomID = properties.items.find(item => item.key === 'Webex_Teams_roomID');
    return roomID ? roomID.value : null;
  });

and write one:

  return await this.api.run(async (context) => {
    context.document.properties.customProperties.add('Webex_Teams_roomID', newRoomID);
    await context.sync();
  });

Where this.api is just window.word using office JS API. I used help from the following repo which is offered by Microsoft themselves, office-js-snippets.

Problem:

I'm not able to run my code in window's machine. After debugging the code, I learned that my code gets stuck at this point: await context.sync();.

Office Versions:

Office Versions in macOS: 16.14.1 (180613).

Office Version in Windows: 16.0.4639.1000 32-bit

Update:

After some digging, I found that I don't have access to context.document.properties.customProperties.items. It will display <permission denied> error. Could this be it?

And I set the Permissions to ReadWriteDocument: <Permissions>ReadWriteDocument</Permissions> Nothing....


Solution

  • It turned out with this MSI build and the API that I'm using, there are some incompatibility issues that result into causing the problems that I had ealier. they suggest I move to 365.