console.log("dealIds: " + dealIds + ", companyId: '" + companyId
+ "', stateInput: '" + stateInput + "'");
let state;
let result = [];
let lastChunk = null;
if (stateInput === "") {
state = { // initial state
lastProcessed: -1
};
} else {
state = JSON.parse(stateInput);
}
const startFrom = state.lastProcessed + 1;
let lastUpdated;
function doIteration() {
let i;
for (i = startFrom; i < dealIds.length; i++) {
bx24.callMethod('crm.deal.update', {
id: dealIds[i],
fields: {
"COMPANY_ID": companyId
}
});
state.lastProcessed = i;
if (stopWatch.getRemainingMillis() <= 0) {
console.log("Достигли ограничения времени запуска");
break;
}
}
return i === dealIds.length;
}
let isFinished = doIteration();
const updatedCount = state.lastProcessed - startFrom + 1;
if (isFinished) {
console.log("Все сделки обновлены, всего:", updatedCount);
} else {
console.log("Сделки обновлены частично, всего:", updatedCount);
}
return {
"stateOutput": JSON.stringify(state),
"isFinished": isFinished
};