Help

Re: Automatically link records based on a Unique ID

1344 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Bazoeki
4 - Data Explorer
4 - Data Explorer

Dear Community,

I want to automatically link records by linking incomming subscriptions (Table called EmailSubscriptions) to certain dogbreeds (!Hondenrassen). I need to match based on a unique id. This ID is in (EmailSubscriptions the “Kind”) and in the Table !Hondentassen also “Kind”. I want to link thise two automatically when a record enters a view. Using the a automation to run the script. I made this script based on some community scripts but it doesn’t seems to work. Can anyone help?

/Define the !Hondenrassen table and query
let cmpTbl = base.getTable(“!Hondenrassen”);
let cmpQuery = await cmpTbl.selectRecordsAsync();

//Define EmailSubsciptions table and query
let cntTbl = base.getTable(“Email”Subscriptions);
let cntQuery = await cntTbl.selectRecordsAsync();

//Loop through the records and find the Kind
for (let record of cmpQuery.records) {
let cmpid = record.getCellValue(“Kind”);

//Loop through linked table and match ID Values
for (let cntRecord of cntQuery.records) {
    if (cntRecord.getCellValue(“Kind”) === cmpid) {
        //Update field
        cmpTbl.updateRecordAsync(record, {
            “Kind”: [{id: cntRecord.id}]
        });
    }
}

}

1 Reply 1

How does a record enter view, though? If it’s via a JSON payload, I’d suggest inserting the data directly into the linked field, assuming the Kind is in the record name of the Hondenrassen table (and if it isn’t, it’s a decent practice to have the name field concatenate all the important bits and pieces via a formula in any frequently linked table).

The code you posted is also pretty malformed but you did post something, plus you’re new, so:

let cntTbl = base.getTable(“Email”Subscriptions);

Nevermind the curly quotation marks, that’s probably the forum frontend doing its thing, but the placement of the closing mark could use some work. Say… 13 characters’ worth of work to the right, eh? :winking_face: Didn’t you get a syntax error while trying to run this?

You’re also overthinking the problem imo, just right-click the linked fields and make sure the permissions are set to something permissive, then take another look at the automations tab, the process usually goes “record enters view > update record > select the record from step 1 > select the linked field >update it with a desired value”.