|
1 | 1 | ---
|
2 |
| -ms.date: 06/09/2022 |
| 2 | +ms.date: 05/20/2025 |
3 | 3 | description: Troubleshoot common problems with Excel custom functions.
|
4 | 4 | title: Troubleshoot custom functions
|
5 | 5 | ms.topic: troubleshooting
|
@@ -38,6 +38,47 @@ Generally, these errors correspond to the errors you might already be familiar w
|
38 | 38 |
|
39 | 39 | Information about custom functions is cached by Office. Sometimes while developing and repeatedly reloading an add-in with custom functions your changes may not appear. You can fix this by clearing the Office cache. For more information, see [Clear the Office cache](../testing/clear-cache.md).
|
40 | 40 |
|
| 41 | +### Clear the custom functions cache when your add-in runs |
| 42 | + |
| 43 | +There may be times when you need to clear the custom functions cache for an add-in deployed to your end users, so that add-in updates and custom functions setting changes are incorporated at the same time. Without triggering a custom functions cache clear, changes to the **functions.json** and **functions.js** files may take up to 24 hours to reach your end users, while changes to **taskpane.html** reach end users more quickly. |
| 44 | + |
| 45 | +> [!NOTE] |
| 46 | +> Once this setting is turned on for a document, it takes effect the next time the document is opened with the add-in. It doesn't apply immediately after the function is called. |
| 47 | +
|
| 48 | +To ensure that the custom functions cache is cleared by your add-in, add the following code to your **functions.js** file, and then call the `setForceRefreshOn` method in your `Office.onReady` call or other add-in initialization logic. |
| 49 | + |
| 50 | +> [!IMPORTANT] |
| 51 | +> This process for clearing the custom functions cache is only supported for custom functions add-ins that use a [shared runtime](../testing/runtimes.md#shared-runtime). |
| 52 | +
|
| 53 | +```javascript |
| 54 | +// To enable custom functions cache clearing, add this method to your functions.js |
| 55 | +// file, and then call the `setForceRefreshOn` method in your `Office.onReady` call. |
| 56 | +function setForceRefreshOn() { |
| 57 | + Office.context.document.settings.set( |
| 58 | + 'Office.ForceRefreshCustomFunctionsCache', |
| 59 | + true |
| 60 | + ); |
| 61 | + Office.context.document.settings.saveAsync(); |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +> [!TIP] |
| 66 | +> Frequently refreshing the custom functions cache can impact performance, so clearing the custom functions cache with `setForceRefreshOn` should only be used during add-in development or to resolve bugs. Once a custom functions add-in is stabilized, stop forcing cache refreshes. |
| 67 | +
|
| 68 | +To disable the custom functions cache clear in your add-in, set `Office.ForceRefreshCustomFunctionsCache` to `false` and call the method in your `Office.onReady` call. The following code sample shows an example with a `setForceRefreshOff` method. |
| 69 | + |
| 70 | +```javascript |
| 71 | +// To disable custom functions cache clearing, add this method to your functions.js |
| 72 | +// file, and then call the `setForceRefreshOff` method in your `Office.onReady` call. |
| 73 | +function setForceRefreshOff() { |
| 74 | + Office.context.document.settings.set( |
| 75 | + 'Office.ForceRefreshCustomFunctionsCache', |
| 76 | + false |
| 77 | + ); |
| 78 | + Office.context.document.settings.saveAsync(); |
| 79 | +} |
| 80 | +``` |
| 81 | + |
41 | 82 | ## Common problems and solutions
|
42 | 83 |
|
43 | 84 | ### Can't open add-in from localhost: Use a local loopback exemption
|
|
0 commit comments