Hello, First time post so apologies in advance...
I have a Deliveries table, The idea is when I select a "ship package" [eg.Floor: Sheathing] it pulls up the Assemble numbers with a lookup field - that correlate to a material list on another table. I then have a script which converts that lookup field into a multiple select field. This all functions correctly.
Now my issue is that i want to select a series of boxes ["Ship" "Ready" Delivered"]. The idea being that i have a script [i have zero programing knowledge and have ai write my scripts], That when "ship" is checked the script hunts through the "Materials Table" using data from the "# Reformat" field and with each record that is found in "Assembly #" to match one of the many possible numbers it checks the "Picklist" box. My script below says it works but it does not check the any boxes.
let deliveryTable = base.getTable("Delivery");
let materialsTable = base.getTable("Materials");
// Fetch all records from the "Delivery" table
let deliveryQuery = await deliveryTable.selectRecordsAsync();
// Fetch all records from the "Materials" table
let materialsQuery = await materialsTable.selectRecordsAsync();
for (let deliveryRecord of deliveryQuery.records) {
// Get the names from the "# Reformat" field
let reformatNames = deliveryRecord.getCellValue("# Reformat");
if (reformatNames && reformatNames.length > 0) {
for (let materialRecord of materialsQuery.records) {
let assemblyNumber = materialRecord.getCellValue("Assembly #");
if (assemblyNumber && reformatNames.some(name => name.name === assemblyNumber)) {
// Check if the "Add Picklist" field exists and is a checkbox
if (materialsTable.fields.some(field => field.name === "Add Picklist" && field.type === "checkbox")) {
// Update the "Add Picklist" field to checked
await materialsTable.updateRecordAsync(materialRecord.id, {
"Add Picklist": true
});
}
}
}
}
}
Can anyone tell me whats wrong here...? I have tried repeatedly to make this work but is does not.
The next step is when i check "Ready" it will remove the pick list check and click the "Ready" box on the materials table. And after that i Check Delivered and it marks the delivery as Checked. Creating date stamps along the way.
Beyond that i hope to automate emails at each stage to notify parties of the shipments progress etc. but first the picklist needs to be created.
Any help is appreciated! - Keith