Feb 06, 2023 08:29 AM - edited Feb 06, 2023 08:30 AM
Hello Everyone , I am new to airtable scripting.
I have a Pretty Basic Question -
I am trying to capture records of 1 row using input variables.
here is my code below.
let inputConfig = input.config();
/*my table name*/
let Sourcetable = base.getTable("Facebook")
/*Airtable Id of row*/
let aid = inputConfig.AirtableID
/*This is a linked record*/
let cname = inputConfig.client console.log(cname)
Cname is a linked record from another table.
When i run cosole.log(cname) it gives me a empty array.
My Question is How do I get the airtable ID of linked records via input config?
Thanks in advance.
Solved! Go to Solution.
Feb 06, 2023 10:28 AM
Hey @codebin!
I created a simple Lead record as an example to work through:
In my automation I've set up two input variables.
The first is the record id of the record that triggered the automation.
The second is the value of the Deals linked record field.
Here's a code snippet that I can use to get the value of the Deals linked record field:
const config = input.config();
const { recordId, deals } = config;
console.log(deals);
Here's what it looks like in Airtable:
Another alternative way of doing this would be to retrieve the record object directly from the table and then call the record.getCellValue() method to get a similar result.
Here's a code snippet:
const config = input.config();
const { recordId } = config;
const tableId = "tbluOb0BJ7NwMiDeZ"
const table = base.getTable(tableId);
const leadRecord = await table.selectRecordAsync(recordId);
// Passing "fldTBY3hA7SJoJZfh" is the same as passing the field name of "Deals".
const dealValue = leadRecord.getCellValue("fldTBY3hA7SJoJZfh");
As you can see, this method will return an array of record objects.
I always prefer to use this method of retrieving record values because I have historically found that script performance degrades rapidly if multiple input variables are being passed to the script.
I have also found that it makes things easier for me to read and maintain as time goes on.
If you use the record.getCellValueAsString() method on the field, then it will return a string of comma separated values.
Definitely recommend that you play around with it a bit. Let us know if you run into any issues or have any additional questions!
Feb 06, 2023 10:28 AM
Hey @codebin!
I created a simple Lead record as an example to work through:
In my automation I've set up two input variables.
The first is the record id of the record that triggered the automation.
The second is the value of the Deals linked record field.
Here's a code snippet that I can use to get the value of the Deals linked record field:
const config = input.config();
const { recordId, deals } = config;
console.log(deals);
Here's what it looks like in Airtable:
Another alternative way of doing this would be to retrieve the record object directly from the table and then call the record.getCellValue() method to get a similar result.
Here's a code snippet:
const config = input.config();
const { recordId } = config;
const tableId = "tbluOb0BJ7NwMiDeZ"
const table = base.getTable(tableId);
const leadRecord = await table.selectRecordAsync(recordId);
// Passing "fldTBY3hA7SJoJZfh" is the same as passing the field name of "Deals".
const dealValue = leadRecord.getCellValue("fldTBY3hA7SJoJZfh");
As you can see, this method will return an array of record objects.
I always prefer to use this method of retrieving record values because I have historically found that script performance degrades rapidly if multiple input variables are being passed to the script.
I have also found that it makes things easier for me to read and maintain as time goes on.
If you use the record.getCellValueAsString() method on the field, then it will return a string of comma separated values.
Definitely recommend that you play around with it a bit. Let us know if you run into any issues or have any additional questions!
Feb 07, 2023 07:46 AM
Thanks a Ton! It works well on my end.