Community experts,
Sorry for the long title. I am very new to coding of any kind and without the community I would have never gotten this far.
Basically, I have a synced table in my base and I have a automation script to link the records based on a field, “Part Number” in one table and “Part#” in the other. The trigger for the automation is “When a record enters a view”. I am linking the record in the synced table, Orders, to the Inventory table. I am able to make this happen with the following code.
var mainTable = base.getTable("Inventory");
var mainView = mainTable.getView("Vendor Source Inventory");
var mainTableRecords = await mainView.selectRecordsAsync({fields: n"Part Number","Vendor_Source_Usage"]});
var lookUpTable = base.getTable("Orders");
var lookUpView = lookUpTable.getView("Completed Vendor Sourced Orders")
var lookUpRangeRecords = await lookUpView.selectRecordsAsync({fields: n"Part#","Order Qty","Updated"]});
for(let record of mainTableRecords.records) {
let lookUpValue = record.getCellValue("Part Number");
let linkArray = l];
for(let rangeRecord of lookUpRangeRecords.records) {
if(rangeRecord.getCellValue("Part#") === lookUpValue) {
linkArray.push(
rangeRecord.id
);
};
};
let d = ]
console.log(linkArray.length)
linkArray.forEach(r => d.push({id: r}));
await mainTable.updateRecordAsync(record, {
'Vendor_Source_Usage': d
});
};
I realize I could do this in a more elegant fashion, but it works. Because of the nature of the workflow and the relatively fast sync rate, I have no worries of hitting the 50 record limit, as long as I can clear the view that is triggering the automation, “Completed Vendor Sourced Orders”, after I link the records.
What I would like to do now is add code to remove the records from “Completed Vendor Sourced Orders”. I have set up a checkbox field called “Updated” that I would like to check, but I can’t seem to make that work.
I tried the following replacement of the second for loop and the check boxes are getting marked but now the records aren’t being linked.
for(let rangeRecord of lookUpRangeRecords.records) {
if(rangeRecord.getCellValue("Part#") === lookUpValue && rangeRecord.getCellValue("Updated") === null) {
linkArray.push(
rangeRecord.id
);
await lookUpTable.updateRecordAsync(rangeRecord, {
'Updated': true
});
};
}
Any help would be greatly appreciated!
Thanks in advance!