Help

Re: Access value of linked record as input variable

Solved
Jump to Solution
1605 0
cancel
Showing results for 
Search instead for 
Did you mean: 
codebin
4 - Data Explorer
4 - Data Explorer

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.

 

 

 

1 Solution

Accepted Solutions
Ben_Young1
11 - Venus
11 - Venus

Hey @codebin

I created a simple Lead record as an example to work through:

Ben_Young1_0-1675707346044.png

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:

Ben_Young1_1-1675707491105.png

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");

Ben_Young1_2-1675707822047.png

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!

See Solution in Thread

2 Replies 2
Ben_Young1
11 - Venus
11 - Venus

Hey @codebin

I created a simple Lead record as an example to work through:

Ben_Young1_0-1675707346044.png

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:

Ben_Young1_1-1675707491105.png

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");

Ben_Young1_2-1675707822047.png

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!

codebin
4 - Data Explorer
4 - Data Explorer

Thanks a Ton! It works well on my end.