Skip to main content

Help with script to combine URL and text

  • June 30, 2021
  • 1 reply
  • 14 views

Forum|alt.badge.img+2

Hi,

Using the following script from this post, I created a field that combines a URL and text:

let tb = base.getTable(“URL Test”);
let query = await tb.selectRecordsAsync();
for (let record of query.records) {
let url = record.getCellValue(“URL”);
let name = record.name;
let text = record.getCellValue(“Text”);
if(url) {
tb.updateRecordAsync(record, {“Rich”: [${text}](${url}) - ${name}})
}
}

I have two questions:
1: Can I make this script complete this task in multiple columns? (for example - perform the script for column “Rich” and then have “Rich2” to repeat the script, but using a different URL column.)
2: This doesn’t work if my URL is coming from a lookup - even if the lookup is a URL. Is there a way to get this to work from a lookup field?

Thanks!
Jeffrey

1 reply

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • June 30, 2021

Lookup fields are tricky. Try using getCellValueAsString instead of getCellValue for the lookup fields.

You can also have the script make changes in multiple columns. There are several different ways. The simplest ways is to duplicate the code. Other ways are to update both fields at the same time. Another variation to consider is to make an array of the updates and then perform the updates in a batch at the end of the script. However, these different ways are more about understanding coding and JavaScript versus using the API.