-
Notifications
You must be signed in to change notification settings - Fork 270
[Excel] (Custom functions) Update low engagement articles #5364
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
Changes from 9 commits
c45976c
74a42b6
ce1f207
f8cfe04
7caae51
95d521d
232d4c8
4dd1c92
55db14c
2b391ef
5f091fe
853d2bb
e79c564
9b057a1
5523722
dbaf3e3
db1acd0
5976a12
aad796c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "MD025": false, | ||
| "MD033": { | ||
| "allowed_elements": ["kbd"] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| --- | ||
| ms.date: 09/09/2022 | ||
| ms.date: 09/19/2025 | ||
| description: Batch custom functions together to reduce network calls to a remote service. | ||
| title: Batching custom function calls for a remote service | ||
| ms.topic: best-practice | ||
|
|
@@ -8,9 +8,18 @@ ms.localizationpriority: medium | |
|
|
||
| # Batch custom function calls for a remote service | ||
|
|
||
| If your custom functions call a remote service you can use a batching pattern to reduce the number of network calls to the remote service. To reduce network round trips you batch all the calls into a single call to the web service. This is ideal when the spreadsheet is recalculated. | ||
| Use batching to group calls to a remote service into one network request. This cuts down the number of trips to your remote service and helps the worksheet finish recalculating faster. | ||
alison-mk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For example, if someone used your custom function in 100 cells in a spreadsheet, and then recalculated the spreadsheet, your custom function would run 100 times and make 100 network calls. By using a batching pattern, the calls can be combined to make all 100 calculations in a single network call. | ||
| ## Key points | ||
|
||
|
|
||
| - Several calls can be combined into one request that runs every short interval (for example, about 100 ms). | ||
alison-mk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Each function call gets a `Promise` that is resolved when the single combined response returns. | ||
| - Shorter intervals show results sooner but send more requests. Slightly longer intervals reduce traffic. | ||
alison-mk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Map errors back to the specific call so one failure does not hide others. | ||
| - Set a reasonable maximum number of items per batch (for example, 500) to keep the request size safe. | ||
| - Cache recent results if many calls use the same inputs. | ||
|
|
||
| Example scenario: 100 cells call the custom function. Instead of 100 network requests, you send one request that lists all 100 operations and then return 100 answers. | ||
alison-mk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [!include[Excel custom functions note](../includes/excel-custom-functions-note.md)] | ||
|
|
||
|
|
@@ -176,7 +185,7 @@ Add the following code to your **functions.js** or **functions.ts** file. | |
|
|
||
| ```javascript | ||
| // This function simulates the work of a remote service. Because each service | ||
| // differs, you will need to modify this function appropriately to work with the service you are using. | ||
| // differs, you will need to modify this function appropriately to work with the service you are using. | ||
alison-mk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // This function takes a batch of argument sets and returns a promise that may contain a batch of values. | ||
| // NOTE: When implementing this function on a server, also apply an appropriate authentication mechanism | ||
| // to ensure only the correct callers can access it. | ||
|
|
@@ -232,6 +241,18 @@ To modify the `_fetchFromRemoteService` function to run in your live remote serv | |
| - Apply an appropriate authentication mechanism. Ensure that only the correct callers can access the function. | ||
| - Place the code in the remote service. | ||
|
|
||
| ## When to avoid batching | ||
|
|
||
| Batching adds a small delay and some extra code. Avoid batching in the following scenarios. | ||
|
|
||
| | Scenario | Negative impact of batching | Recommendation | | ||
| |----------|-------------------|----------------| | ||
| | Single or very few calls | Extra wait for timer | Call service directly if list is still empty | | ||
| | Very large input data per call | Request might get too large | Limit size or send those calls alone | | ||
| | Some calls are much slower than others | One slow call delays faster ones | Group slow types separately | | ||
| | Need near‑instant result (less than 50 ms) | Timer adds delay | Use a shorter timer or skip batching | | ||
alison-mk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| | Server already combines work | No benefit | Skip batching on the client | | ||
|
|
||
| ## Next steps | ||
|
|
||
| Learn about [the various parameters](custom-functions-parameter-options.md) you can use in your custom functions. Or review the basics behind making [a web call through a custom function](custom-functions-web-reqs.md). | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.