Jan 08, 2024 06:11 PM - edited Jan 09, 2024 09:57 AM
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:
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
})
} ;
Solved! Go to Solution.
Jan 09, 2024 11:01 AM
Hey @Shawn_Titus!
Let me know if there's something I'm missing here, but since you're just unlinking the battery record from the trailer record, you don't actually need to update the trailer record at all. You can simply clear the value of the battery record's trailer relationship.
This resolves the complexity that comes with having to selectively write a new, filtered set of battery relationships to the trailer record. You don't even have to script such an update.
Again, maybe there's a layer of complexity to your requirements that I'm not understanding upon first read. Let me know if there are any more applicable details.
Jan 09, 2024 11:01 AM
Hey @Shawn_Titus!
Let me know if there's something I'm missing here, but since you're just unlinking the battery record from the trailer record, you don't actually need to update the trailer record at all. You can simply clear the value of the battery record's trailer relationship.
This resolves the complexity that comes with having to selectively write a new, filtered set of battery relationships to the trailer record. You don't even have to script such an update.
Again, maybe there's a layer of complexity to your requirements that I'm not understanding upon first read. Let me know if there are any more applicable details.
Jan 09, 2024 11:07 AM
@Ben_Young1 - you are exactly right! I got so bogged down looking at it from the trailer perspective, I didn't think about it from the battery perspective. Thanks!