2

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)

2
  • Just a sanity check: Did you define a Shared.Url in the <Resources> section of the manifest? Commented Jun 12, 2020 at 18:02
  • It is defined in correctly in the <Resources> section. I believe that's why my initial state is being shared. Commented Jun 13, 2020 at 1:05

1 Answer 1

2

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 }.
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the feedback. I tried this out and no change. I think another red flag that something is off is that I also cannot access the Excel context object like the documentation shows. This feature plus the window.sharedState are part of the shared statement api based on the docs.
Or, if you want to start with a sample that doesn't require any building or deployment, put this manifest on a file share, and side-load it - github.com/OfficeDev/custom-functions/blob/master/addins/…. All of the code is in the same GitHub folder.
This sample is great. I checked it against my manifest file and everything looks good. Here is my manifest.xml file. manifest.xml file link: gist.github.com/thunter05/60dbb0cdca986aaeccd0f2e5e7afe17f
Your manifest does look good. It was even looking good yesterday. If it wasn't good, you'd see an installation error. I suspect your JavaScript is still bad. BTW, what do you see - an error or just no effect? Are you able to create a function that returns a constant number without any side effect, and can you use it in a formula?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.