Updating record when matches with other table

Topic Labels: Scripting extentions
Jump to Solution
1214 7
Showing results for 
Search instead for 
Did you mean: 
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi all! I’ve been working on utilizing scripting within automations for a project. When a record in a table “MPList” is updated, I want to see if that record’s sort name matches any sort names in another table “memList”. If there is a match, I want the trigger record (from MPList) to be updated.

I’m attaching my code below, and I think that one issue I’m running into may be with the input.config() process. The “toMatch” string in the test output window displays the ID, Name, and color for the text field it was pulled from. So, I’m not sure whether the Name of toMatch is correctly being tested for equality with the “Sort Name” field from the other sheet on line 9.

let toMatch = input.config().toMatch;
let mpList = base.getTable("Imported");
let memList = base.getTable("Members");
let query = await memList.selectRecordsAsync();
let result = false;
let member = false;

for (let record of query.records) {
    if (record.getCellValue("Sort Name") == toMatch) {
        await mpList.updateRecordAsync(record, {
    "Member": true });
        member = record.getCellValue("Sort Name");
        result = true;

output.set("matchFound", result)
output.set("tested", member)

Any help would be much appreciated! Thank you so much.

1 Solution

Accepted Solutions

Assign input.config() to a variable. Then pull the properties from the variable.

let inputConfig = input.config()
let toMatch = inputConfig.toMatch
let atID = inputConfig.atID

See Solution in Thread

7 Replies 7

Welcome to the Airtable community!

What are the field types of the fields in question? Can you provide screen shots?

Sometimes the cell read value and the value passed to input variables have different formats.

I recommend that you console.log the variable values so that you can see the actual values being considered.

Thank you so much! Both of the fields are long text fields. I’m attaching a screenshot of the test with your advice to use console.log (thank you for that, I’d totally missed that possibility), redacting the exact names involved!

From that, it does totally seem like the query is pulling out the values I want, but the toMatch value from input.config is not returning just the cell value. Is there a best way for me to configure that value so that it returns the field contents (specifically the name)?

Screen Shot 2021-07-16 at 12.47.40 PM

Edit: also attaching the full view of how I set up toMatch from the left window:
Screen Shot 2021-07-16 at 12.51.59 PM

It looks like your sort name field is a single select, not a long text field. Has the field type changed?

What happens if you re-test the trigger and then try running the automation again?

You are brilliant and I’m very grateful for your patience with this. I had earlier changed the field type form a single select to a long text field and re-set up the trigger, but testing the trigger again did the trick and toMatch now shows up as just the name string.

New question, for which I apologize: On line 10, when I mean to update the record from MPList/the record that was updated to trigger this whole thing, I’m calling ‘record’ from the query/the matching record in memList. If I try to have a line say

let atID = input.config().atID;

where I’m trying to pull out the airtable ID for the original record, I am told I can only call input.config() once. Is there another best practice for passing the original record’s ID to the updateRecordAsync function?

Thank you again.

Assign input.config() to a variable. Then pull the properties from the variable.

let inputConfig = input.config()
let toMatch = inputConfig.toMatch
let atID = inputConfig.atID

Thank you again for all of this! I think everything is set now, and I’m extremely grateful for your help.

@Hadley_Parum Glad to know that you got the answer you were seeking! If you would, please mark the appropriate comment above from @kuovonne as the solution to your question. This helps others who may be searching with similar questions. Thanks!