Help

Automation - Updating record with just one item from another table

Topic Labels: Automations
2409 4
cancel
Showing results for 
Search instead for 
Did you mean: 
alexh
5 - Automation Enthusiast
5 - Automation Enthusiast

I need to set up a workflow where users register through a form with their email address, and in some cases, an optional Group ID I will pre-fill using URL parameters. Those users then need to be assigned a unique URL (taken from another table) and then they need to get an email that confirms their registration and shares that URL. 

To do this, I have two tables:

  • registrationInfoTable: Captures email addresses (and sometimes Group IDs)
  • testLinksTable: A static list of all the available unique URLs. 

My test base is here for reference: https://airtable.com/appX64txDWlNUmTGO/shryhyKtLyjgBdQiH

The automation I've been using is called "Update registration with testLink" and features the following steps:

  1. Trigger: When a record is created in registrationInfoTable. I have also tried a form submission trigger and they seem to be the same in my case. This seems to be working.
  2. Find records: I have a formula in the testLinksTable that designates each link as "assigned" or "unassigned" based on whether that record is linked to a record in the registrationInfoTable. This seems to be working.
  3. Run a script: This seems to be where things are failing for me. I want the script to take the input from step 2, select just one of those, and create the connection between the two tables, which should automatically put a single unassigned link over for that user. Here's the script:

 

 

// Linking the table
let table = base.getTable('registrationInfoTable');

// Assume 'unassignedLinks' is passed as an input variable to the script
let inputConfig = input.config();

// Array of Record IDs from the 'Find Records' step
let unassignedLinks = inputConfig.unassignedLinks;

// Record ID from the trigger step
let newRecordId = inputConfig.newRecordId;

// Ensure there are unassigned links to choose from
if (unassignedLinks.length > 0) {
   
    // Choose the first unassigned link from the provided array
    let chosenLink = unassignedLinks[0];

    // Ensure we have a valid Record ID for the new registration and a chosen test link
    if (newRecordId && chosenLink) {
        // Update the registrationInfo record with the chosen testLink
        await table.updateRecordAsync(newRecordId,{['testLinks']: [{id: chosenLink}]
        });
    } else {
        console.error('Error: Record ID or chosen test link is undefined.');
    
    } 

} else {
    console.error('No unassigned testLinks available.');
}

 

 

When I run this, I get the following error code, which I haven't been able to figure out:

 

 

ERROR
Error: Field "fldCNPJxVSoQjRW55" cannot accept the provided value.
    at main on line 22

 

 

When I looked into it, fldCNPJxVSoQjRW55 is the testLinks field in registrationInfoTable, which is the field I use to associate the records across the two tables. Maybe there's some kind of a limitation to this kind of field? I'll try just pulling the URL across but then I will need to write some kind of a script that would designate the chosen URL as "assigned" so it doesn't get picked again and I don't know how to do that.

I've been looking through Community posts for a few days now and am still having issues getting my automation to work, which is why I'm posting this here. If there are other threads you think might solve my problem I welcome the help. Once I've figured this out, then I need to add a step (or add a new automation flow?) that will send the user an email.

Thanks so much!

~Alex

4 Replies 4
Nora_Brown
6 - Interface Innovator
6 - Interface Innovator

Rather than updating the record in the script, add some output from the script like `output.set('chosenLink', chosenLink)` and then add a separate Update Record step. This will allow you to test more easily and see that the `chosenLink` output is what you expect. Are you sure that the `unnassignedLinks` is an array of record ID's? And not an array of records or something else? You can always `console.log()` things at various steps in your code so you can see the values when testing.

Could you provide a screenshot of your automation setup as well as how you're setting up your input variable?  (If you could provide a read only link to your base that'd be best as that'd include the automation setup and would make things a lot easier to debug)

Could you do a console.log of unassignedLinks?

Thank you Adam! 

Here are a few screenshots of the automation setup in Airtable. The read-only link should be this one: https://airtable.com/appX64txDWlNUmTGO/shryhyKtLyjgBdQiH, but when I look at it in an anonymous browser I'm not able to see the automation details so I may have the wrong settings enabled. 

I will reply again with a console.log as soon as I can.

 

Hi Alex, for your input variable, could you try setting it up so that it uses the Airtable record IDs instead like so?

Screenshot 2024-03-23 at 11.51.48 AM.png
The error in your screenshot also seems to indicate a new error where that field can't be found; if you could change that field ID value back into the field name that should remove that error as well I think