const dealIds = [];
let lastSeenId = 0;
let loadedActivities = undefined;
do {
loadedActivities = bx24.callMethod('crm.activity.list',
{
start: -1,
order: {'ID': 'ASC'},
filter:
{
"OWNER_TYPE_ID": 2, // сделка
"COMPLETED": "N",
'>ID': lastSeenId
},
select:[ "ID", "OWNER_ID" ]
}
)
console.log(`Загружены ${loadedActivities.length} незавершенных дел`);
if (loadedActivities.length > 0) {
dealIds.push(
...loadedActivities.map((element) => parseInt(element.OWNER_ID))
);
lastSeenId = loadedActivities[loadedActivities.length - 1].ID;
}
} while (loadedActivities.length == 50);
;
return {
"dealIds": [...new Set(dealIds)] // берем из dealIds только уникальные значения
};