Tony Hunter
Tony Hunter

Reputation: 31

Excel JS Add-In - Shared Runtime Not Working

I'm trying to use the "Shared Runtime" to work with my Excel JS Add-In, but it's not working. Below are the docs that I have been reviewing. Below are screenshots of my project. It looks like I'm able to set an initial state but my custom function is not updating window.sharedState. I also tried using the Excel context object but that is not working either.

Documentation Links

  1. https://learn.microsoft.com/en-us/office/dev/add-ins/tutorials/share-data-and-events-between-custom-functions-and-the-task-pane-tutorial
  2. https://learn.microsoft.com/en-us/office/dev/add-ins/excel/configure-your-add-in-to-use-a-shared-runtime

Project Screenshots

My Excel Add-In Project (screenshot #1)

My Excel Add-In manifest.xml file (screenshot #2)

Upvotes: 2

Views: 1492

Answers (1)

Thanks for sharing the key parts of your project! Your screenshots are very helpful!

The fact that your custom function can read the shared state is a good sign.

The reason why your custom function is not changing the shared state may be because you are not providing a valid JSON. I see several problems with the values you are trying to set:

  1. The { ... } must be a literal, i.e. you cannot use variables inside. Thus, things like { oldVal: originalVal } are not valid. If you want to use variables, you'll have to programmatically assign those values, e.g.
window.sharedState.test = {};
window.sharedState.test.oldVal = originalVal;
  1. The literal { first, second } is not valid - it doesn't adhere to the property: value pattern.
  2. While JavaScript and TypeScript may allow unquoted property names, it is good to develop the habit of quoting them like { "something": 42 }.

Upvotes: 2

Related Questions