Skip to main content

Have a script that combines url+title - Need edit for multiple url & titles in each field

  • June 15, 2022
  • 1 reply
  • 0 views

Hello,

I have a company review database. On Table 1 is the Companies. Table 2 has the Reviews of those companies, with links to those individual entries. Each company has multiple reviews submitted by various people.

I have linked Companies to Reviews, done a lookup for the url + title I want (from Reviews). The script I have transforms those into hyperlinks successfully., but ONLY if there is only 1 url and 1 title in those fields.

Because each company has multiple reviews submitted by different people, each field has multiple entries (both url and title), and my script is resulting in one run-on link that shoved all the titles together. Any ideas how to edit this script to separate each of these out?

I used:

let tb2 = base.getTable("Companies");
let query2 = await tb2.selectRecordsAsync();
for (let record of query2.records) {
    let url = record.getCellValue("Individual Rating links (from Reviews)");
    let text = record.getCellValue("Job Title (from Reviews)");
    if(url) {
        tb2.updateRecordAsync(record, {"Rich Text Individual Ratings": `[${text}](${url})`})
    }
}

Thanks in advance!

1 reply

TheTimeSavingCo
Forum|alt.badge.img+18

Hi Sadie, try this

let tb2 = base.getTable("Table 1");
let query2 = await tb2.selectRecordsAsync();
for (let record of query2.records) {
    let url = record.getCellValue("Individual Rating links (from Reviews)");
    let text = record.getCellValue("Job Title (from Reviews)");
    if(url) {
        let textToUse = ""
        for (let i = 0; i < url.length; i++){
            textToUse = textToUse + '[' + text[i] + '](' + url[i] + '),'
        }
        tb2.updateRecordAsync(record, {"Rich Text Individual Ratings": textToUse})
    }
}

You can find it set up in a base here


Reply