In my scenario, I have a trailer that may have multiple batteries assigned to it. When a battery needs to be removed, the client brings up the battery detail in an Interface and clicks 'Remove'. This launches an automation where multiple things occur:
- A ticket is opened for the battery
- Notes are added to both the trailer (in the trailer table) and the battery (in the battery table).
Then, I want to run a script to remove the battery from the trailer.
I found another post that was doing something similar, and after much troubleshooting (I'm new to coding), I've got it down to one error that I'm not sure how to troubleshoot.
Error: Request parameters failed validation.
at main (script:14)
A few notes, yes, the input values from the automation are lists, but there will only ever be one value in the list, which is why I used JSON.stringify. I also suspect the code in line 13 may be wrong.
Thanks so much for your help!
Code:
const inputConfig = input.config();
const inputTrailer = inputConfig['trailer'];
const inputBattery = inputConfig['battery'];
const myTrailerJSON = JSON.stringify(inputTrailer);
const myBatteryJSON = JSON.stringify(inputBattery);
const trailerTable = base.getTable('Level4-Trailer');
const batteryTable = base.getTable('Level3-Head');
const myTrailerRecord = await trailerTable.selectRecordAsync(myTrailerJSON);
const myBatteryRecord = await batteryTable.selectRecordAsync(myBatteryJSON);
if (myTrailerRecord?.getCellValue('linkBuildAssignBatt') !== null) {
let removeBatteryRecord = myTrailerRecord?.getCellValue('linkBuildAssignBatt').filter( record => (record.name != 'L3Barcode'));
await trailerTable.updateRecordAsync(myBatteryJSON, {
'linkBuildAssignBatt' : removeBatteryRecord
})
} ;