Jan 18, 2022 12:36 PM
Hello!
I’m trying to edit a script that I already have. To do so, I need to be able to get values from a Link to Another Record. The linked record is on a different table. I’ve been using .getCellValue() for most cases, but it doesn’t seem to be helping me here. Right now, when I run the .getCellValue, it returns an Object, and when I run .getCellValue().values, it outputs “function”.
How can I get a specific field off of the linked record?
Solved! Go to Solution.
Jan 18, 2022 04:26 PM
Here are two approaches…
You could use a lookup field to pull over the value from the other table - this way it’s already part of the selected record when your script runs.
If you don’t want to do that, you’ll need to select the record on the other table in order to use the getCellValue()
method.
If the linked record field you’re referencing only has one value in it (I.e is only linked to one record on the other table), the following code should work for you:
let recordToSelect = selectedRecord.getCellValue("Linked Record Field Name")[0];
let recordFromOtherTable = await otherTable.selectRecordAsync(recordToSelect.id);
let valueFromOtherTable = recordFromOtherTable.getCellValue("Field From Other Table");
The above is drastically simplified but if you want to share more info I’m happy to help you adjust for your code / use case :slightly_smiling_face:
Jan 18, 2022 04:26 PM
Here are two approaches…
You could use a lookup field to pull over the value from the other table - this way it’s already part of the selected record when your script runs.
If you don’t want to do that, you’ll need to select the record on the other table in order to use the getCellValue()
method.
If the linked record field you’re referencing only has one value in it (I.e is only linked to one record on the other table), the following code should work for you:
let recordToSelect = selectedRecord.getCellValue("Linked Record Field Name")[0];
let recordFromOtherTable = await otherTable.selectRecordAsync(recordToSelect.id);
let valueFromOtherTable = recordFromOtherTable.getCellValue("Field From Other Table");
The above is drastically simplified but if you want to share more info I’m happy to help you adjust for your code / use case :slightly_smiling_face: