Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to pass configuration parameters to custom function's JavaScript context #130

Closed
alaincao opened this issue Mar 29, 2019 · 10 comments
Assignees

Comments

@alaincao
Copy link

Hello there, this is more a question than an issue ; I hope this is the right place to ask ...

How can I pass general server configuration values to the custom functions context?
e.g. I have no problem within the taskpane context because I have access to a DOM where I can generate things like

<script>
window.myparameters = { napoleonsWhiteHorseColor:"Probably black" };
</script>
<script src="myaddin.js"/>

but I have difficulties understanding how to do that for the CustomFunctions context since there is no HTML file nor DOM...
I mean, without access to window.location.href, I'm not even sure how to get the current server's URL (without hard-coding it which I am definitively not going to do) ; I could use that to make some request to/someoptionalvirtualpath/myparameters.json.

I thought about polling the AsyncStorage regularily and wait for the taskpane to post them there, but that really doesn't seem right ...

Subsidiary question: is there a way to use more than 1 JavaScript file for the CustomFunctions context? I haven't seen any way in the manifest.xml.
e.g. { file_1: "http://server/parameters_generated.js", file_2: "http://server/myaddin.js" }

Thank you!

@akrantz
Copy link
Contributor

akrantz commented Mar 29, 2019

Yes, AsyncStorage can be used to write the configuration info from the taskpane code and then be read from the custom functions code.

You need to bundle the JavaScript for custom functions into a single file. The code here uses webpack for this.

@alaincao
Copy link
Author

Ok, I see, that's what I feared. Thank you for the response.

So my question becomes: will there ever be some kind of "push notifications" between the CustomFunctions and taskpane contexts like Office.context.ui.messageParent() that is used between popup windows and their parent?

Sorry, another one: where are stored the AsyncStorage values (when used from the online Excel) ?
In the browser's local storage or would it require some HTTP requests to some server ?
i.e. what would be the performance impact of using them / what would be the stored values lifetime?
I haven't found an answer to this in the documentation.

@keyur32
Copy link
Collaborator

keyur32 commented Apr 8, 2019

Hi @alaincao, yes, we are working on a 'dispatch' model so you don't have to continuously poll. This will be a way to send messages and won't persist to disk. We'll share info during our Custom Functions call, but will not on our V1. Fill this out if you want to join our weekly call and I'll reach out: https://aka.ms/customfunctionscall.

On Excel Online (and currently on Mac), AsyncStorage uses the browsers localstorage. I'll make a note for @davidchesnut / @mscharlock to add this to docs. thanks!

@Reezaali
Copy link
Contributor

Reezaali commented Apr 8, 2019

Internal bug# 3281128

@davidchesnut
Copy link
Member

Just an update that we published info about the Storage object usage of browser localstorage on the Mac (around May 1). See https://docs.microsoft.com/office/dev/add-ins/excel/custom-functions-save-state. @keyur32 I'll remove myself from the assignee list on this issue. Thanks!

@davidchesnut davidchesnut removed their assignment Jun 19, 2019
@zliebersbach
Copy link

@keyur32 Thanks for the updates on this issue! Just wondering what the current status is on the new "dispatch" model? We have some functionality ready to go with this feature 🙂

@keyur32
Copy link
Collaborator

keyur32 commented Sep 10, 2019

We are working on the documentation and release for insiders right now :)

@ElizabethSamuel-MSFT
Copy link
Contributor

@davidchesnut Any update on this? Thanks.

@davidchesnut
Copy link
Member

Hi @alaincao, following up on this thread, we have a preview feature that allows you to put the custom functions in the same context as the task pane, so they are both effectively using the same DOM. You can then share data or call functions as needed. For more information see Tutorial: Share data and events between Excel custom functions and the task pane (preview). This is the planned solution to your question going forward. Please let us know if you have any feedback on this approach. Thanks!

@keyur32
Copy link
Collaborator

keyur32 commented Jul 30, 2020

Marking closed as it looks to not have had any response since last note. Please re-activate if further help is still needed. The feature David mentioned above, was using the Shared Runtime, and is also now generally available. Thanks!

@keyur32 keyur32 closed this as completed Jul 30, 2020
millerds added a commit to millerds/Excel-Custom-Functions that referenced this issue Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants