Help

Re: Script error when removing record from linked field (Automation triggered in Interface Designer)

Solved
Jump to Solution
1173 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Shawn_Titus
5 - Automation Enthusiast
5 - Automation Enthusiast

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:

  1. A ticket is opened for the battery
  2. 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
})
} ;

 

 

 

 

1 Solution

Accepted Solutions
Ben_Young1
11 - Venus
11 - Venus

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.

See Solution in Thread

2 Replies 2
Ben_Young1
11 - Venus
11 - Venus

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.

@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!