mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-08-06 17:36:53 +01:00
* Add P0 integration and control add-in guidance Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 02baffe8-0600-430d-81fa-a9993685e7cb * Correct API part multiplicity guidance Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 02baffe8-0600-430d-81fa-a9993685e7cb * Refine API part multiplicity guidance Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 1c37924e-9749-4e63-9d58-bd73d659f736 --------- Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com>
74 lines
1.8 KiB
JavaScript
74 lines
1.8 KiB
JavaScript
const pendingChunks = [];
|
|
let callInProgress = false;
|
|
let transferHalted = false;
|
|
|
|
function sendRows(rows, maxArgumentsBytes) {
|
|
if (transferHalted)
|
|
throw new Error("Retry or discard the failed chunk before sending more rows.");
|
|
|
|
const encoder = new TextEncoder();
|
|
const chunks = [];
|
|
let chunk = [];
|
|
const argumentBytes = (payload) =>
|
|
encoder.encode(JSON.stringify([payload])).length;
|
|
|
|
for (const row of rows) {
|
|
if (argumentBytes(JSON.stringify([row])) > maxArgumentsBytes)
|
|
throw new Error("A row exceeds the configured payload limit.");
|
|
|
|
const candidate = JSON.stringify([...chunk, row]);
|
|
|
|
if (argumentBytes(candidate) <= maxArgumentsBytes) {
|
|
chunk.push(row);
|
|
continue;
|
|
}
|
|
|
|
chunks.push(JSON.stringify(chunk));
|
|
chunk = [row];
|
|
}
|
|
|
|
if (chunk.length > 0)
|
|
chunks.push(JSON.stringify(chunk));
|
|
|
|
pendingChunks.push(...chunks);
|
|
sendNextChunk();
|
|
}
|
|
|
|
function sendNextChunk() {
|
|
if (callInProgress || pendingChunks.length === 0)
|
|
return;
|
|
|
|
callInProgress = true;
|
|
const payload = pendingChunks[0];
|
|
Microsoft.Dynamics.NAV.InvokeExtensibilityMethod(
|
|
"StoreRows",
|
|
[payload],
|
|
false,
|
|
() => {
|
|
pendingChunks.shift();
|
|
callInProgress = false;
|
|
sendNextChunk();
|
|
},
|
|
() => {
|
|
callInProgress = false;
|
|
transferHalted = true;
|
|
showTransferError();
|
|
});
|
|
}
|
|
|
|
function retryFailedChunk() {
|
|
if (!transferHalted)
|
|
return;
|
|
|
|
transferHalted = false;
|
|
sendNextChunk();
|
|
}
|
|
|
|
function discardFailedChunk() {
|
|
if (!transferHalted)
|
|
return;
|
|
|
|
pendingChunks.shift();
|
|
transferHalted = false;
|
|
sendNextChunk();
|
|
}
|