Help

Populating a new table with entries from lined fields

Topic Labels: Scripting extentions
672 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Arwel_Brown
4 - Data Explorer
4 - Data Explorer

Hi! I’m attempting at the moment to automate a flights table so passengers know where they’re flying to and when, etc etc. I’m having a huge issue with the linked fields!

Here is the current table design;

image

(confusingly, ‘Name’ here is in reference to flight name, but the principle will be exactly the same as extracting the Confirmation)

Where ‘Confirmation’ is a six digit flight confirmation number (PNR number), coming from the ‘Confirmations’ table. For some reason, whenever I attempt to populate that field with my script, with a linked record from Confirmations, it shouts at me telling me the linked record ID does not exist! A dumbed down version of my code is below, it’s not too dissimilar to what is being done in this forum post (Adapting script to paste into linked field). The record is being created just fine, but the update with the value from the linked field is where things go wrong. I am a huge airtable newbie and am a bit lost!

// Read table info

let flightsTable = base.getTable('Flights');
let passengerManifestTable = base.getTable('Passenger_Manifest');
let pnrTable = base.getTable('Confirmations');
let passengersTable = base.getTable('Passengers');
let passengerFlightsTable = base.getTable('Passenger_Flights'); // Table to be populated

// pull out records

let passengerManifestQuery = await passengerManifestTable.selectRecordsAsync({
     fields: passengerManifestTable.fields
});
let passengerFlightsQuery = await passengerFlightsTable.selectRecordsAsync({
     fields: passengerFlightsTable.fields
});
let flightsQuery = await flightsTable.selectRecordsAsync({
     fields: flightsTable.fields
});
let pnrQuery = await pnrTable.selectRecordsAsync({fields: pnrTable.fields});

let flightPNR = pnrQuery.records[0];
let passengerName = passengerManifestQuery.records[0].name;

let newPassengerFlightRecord = await passengerFlightsTable.createRecordAsync({
    'Passenger Name': passengerName
});

console.log(newPassengerFlightRecord);

let updatedPassengerFlightRecord = await passengerFlightsTable.updateRecordAsync(newPassengerFlightRecord, {
    'Confirmation': [{id: newPassengerFlightRecord}]
});

Any help would be hugely appreciated, thanks in advance guys!

0 Replies 0