Help

Help with script to combine URL and text

1331 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Jeffrey_Brandt
6 - Interface Innovator
6 - Interface Innovator

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 1

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.