Upload and save files
Binary files could be uploaded for the records - they are references in respective file-list fields.
// get all deals with 1000+ sum from CRM workspace and attach invoices to them
async function attachInvoicesToBigDeals() {
const allDeals = await getBigDeals();
for (const deal of allDeals) {
const filePath = `${__dirname}/_files/${deal.id}.pdf`;
if (!fs.existsSync(filePath)) continue;
deal.transition = "edit";
deal.attachments = [
{
file_uid: fileUid,
id: fileUid,
pending: true,
title: `Invoice for ${deal.id}.pdf`,
},
];
}
await this.comind.records.save(allDeals);
console.warn(`Saved ${data.length} deals with attachments`);
}