Help

Re: Creating a hyperlink from two fields

2958 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Nick_Truch
5 - Automation Enthusiast
5 - Automation Enthusiast

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:

  • Formula field: doesn’t seem to like html so I can’s put … <@ href="{Product Link}" target="_blank">{Product Name}</@> … (I’ve put @ instead of a so you can see the code)
  • Button: I can select the url field but there no way to add a field variable to the hyperlink/button text

Anyone else having this issue?

Many thanks
Nick

12 Replies 12

Is it possible those don’t have data in the URL field?

Are you looking at a sorted view vs the unsorted table?

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!

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