Mar 10, 2023 02:15 AM
Hi all
I've just got into scripting, and have fallen at the first hurdle.
Solved! Go to Solution.
Mar 10, 2023 03:24 AM - edited Mar 10, 2023 03:32 AM
To answer my own question for anyone else struggling to work it out. getCellValueAsString() was the solution for me. I don't know if this is the best way of doing it. But this is how you can get whatever field values you need.
I'm printing them here. But you could instead, add each recordDetails to an array.
(disclaimer, I'm not an expert)
Additionally I believe it is preferable to only load the fields you need, to save memory. So you should replace line 2 this code to something like:
Mar 10, 2023 03:24 AM - edited Mar 10, 2023 03:32 AM
To answer my own question for anyone else struggling to work it out. getCellValueAsString() was the solution for me. I don't know if this is the best way of doing it. But this is how you can get whatever field values you need.
I'm printing them here. But you could instead, add each recordDetails to an array.
(disclaimer, I'm not an expert)
Additionally I believe it is preferable to only load the fields you need, to save memory. So you should replace line 2 this code to something like:
Mar 10, 2023 01:18 PM
Yah, that looks correct.
One tip - I prefer to use .map() .filter() and .reduce() instead of for loops.
I *think* my updated code below should work for you, but you might want to edit/remove the .filter() as it will filter out any non-matched records. I highly doubt any of your records have the name "An example filter string" 😜
let table = base.getTable("Contacts");
let query = await table.selectRecordsAsync({
fields: ["Full Name", "Last Name", "Contact Type"]
});
let recordDetails = query.records
.filter((record) => record.name === "An example filter string")
.map((record) => ({
fullName: record.getCellValueAsString("Full Name"),
lastName: record.getCellValueAsString("Last Name"),
contactType: record.getCellValueAsString("Contact Type")
}));
console.log(recordDetails)