Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Feb 04, 2021 01:23 AM
Hi,
Firstly … sorry for such a basic question but I’ve been through pretty much all the options a few times and still a blank look on my face!
I’m planning to migrate over from Knack.com, here it’s easy to set a url column of data and change it to a hyperlink so it shows another field’s data as the hyperlink text. So for example you have a column of Product Titles and when clicked they go to the url in a new window. Simples! Also their formula field accepts html so you can create <a href … code with the other field variables.
But … how do you do this in AirTable. I’m hoping there is a way as I was under the impression AirTables is an upgrade and more developed. Fingers crossed!
Here is what I’ve tried:
Anyone else having this issue?
Many thanks
Nick
Feb 04, 2021 12:46 PM
Is it possible those don’t have data in the URL field?
Are you looking at a sorted view vs the unsorted table?
Feb 04, 2021 01:03 PM
Yes your absolutely right … I had a few Curators with our url data. Which was only a temp thing. In future this will be a required field so this shouldn’t be an issue … I’m hoping!
Am cleaning up that part of the data and will re-run … in theory I guess it should all complete and run ok.
Thanks again for all your help!
Feb 04, 2021 08:24 PM
One thing is missing: the await
keyword in front of the update command. Not waiting for each record to update before attempting to update the next record is likely why only a handful of records were updated. Try this modification:
let tb = base.getTable("Curators");
let query = await tb.selectRecordsAsync();
for (let record of query.records) {
let url = record.getCellValue("Curator Link");
let text = record.getCellValue("Curator Name");
if (url) {
await tb.updateRecordAsync(record, {
"Curator with Link": "[" + text + "](" + url + ")\n"
})
}
}
The downside to this method is that the total update will take a long time. Waiting for records to update means that only 2-3 records per second can be updated. A better option is to collect all updates into an array, and update them in batches of 50. Here’s the change to make that happen:
let tb = base.getTable("Curators");
let query = await tb.selectRecordsAsync();
let updates = [];
for (let record of query.records) {
let url = record.getCellValue("Curator Link");
let text = record.getCellValue("Curator Name");
if (url) {
updates.push({
id: record.id,
fields: {
"Curator with Link": "[" + text + "](" + url + ")\n"
}
});
}
}
while (updates.length > 0) {
await tb.updateRecordsAsync(updates.slice(0, 50));
updates = updates.slice(50);
}