Skip to main content
Question

Script to update a linked field


KenD
Forum|alt.badge.img+2
  • New Participant
  • 1 reply

Hello,

I don’t have a lot of scripting experience but feel like this one should be simple. However, I can not find my error; it’s probably something super simple and I’m just not seeing it.

Here are the two simple tables I have:

 

So in the Day table, when the Week linked field is missing, I want a script to automatically update the field.

 

Here is my script:

 

The error is:

 

I know the weekID is correct because I can paste the result in the Week field and it works but unfortunately the script can not do it.

 

Thanks in advance, I hope this is easy one!

4 replies

TimBeeston
Forum|alt.badge.img+3
  • Participating Frequently
  • 18 replies
  • April 3, 2025

Hey ​@KenD,

You're getting this error because the WeekID string you've constructed (shown below) is just a display value for end users - it's not the record ID that Airtable scripting needs to create links between tables.


record.getCellValue("WeekNum") + "-" + getInitials(record.getCellValue('Employee').name)
 

To fix this, you need to add these steps to your script:

  1. Use your created weekID value to search your Week table and find the matching record
  2. Get the actual record ID from that found record
  3. Use that record ID (not the display value) to set the Week field

If you need any further help doing that, let me know.  

Tim
minnow.tech


 


TheTimeSavingCo
Forum|alt.badge.img+28

Ah, yeah this is a lot messier than it seems at first glance

  • If the generated Week ID doesn’t exist in the other table, then you’ll need to create new records in that table, grab their IDs, and then link them to your original records
  • If they do exist, then you’ll need to grab their record IDs by querying the other table and looping through the results

As an alternative, you could try creating an array where each object contains the record ID and the formatted Week ID you want and then outputting it with ‘output.set’

[
  {
    'recordId': recxxx,
    'Week ID': 2025-04-01 JD
  }
]

I think you should then be able to use a Repeating Group on that output, and then you could use an Update Record action with it


Alexey_Gusev
Forum|alt.badge.img+23

Hi,
There are several ways to do it without code.
But if you interested in code, the trick is to query Weeks table and get record id by it’s name (name is a value of primary field)
By way, you forget to check ‘when the Week linked field is missing’

I would do something like that, it works but linter don’t like the result array despite i filter it for invalid values (for cases when such Person and Week is absent in Weeks table)

 

 


KenD
Forum|alt.badge.img+2
  • Author
  • New Participant
  • 1 reply
  • April 3, 2025
TimBeeston wrote:

Hey ​@KenD,

You're getting this error because the WeekID string you've constructed (shown below) is just a display value for end users - it's not the record ID that Airtable scripting needs to create links between tables.


record.getCellValue("WeekNum") + "-" + getInitials(record.getCellValue('Employee').name)
 

To fix this, you need to add these steps to your script:

  1. Use your created weekID value to search your Week table and find the matching record
  2. Get the actual record ID from that found record
  3. Use that record ID (not the display value) to set the Week field

If you need any further help doing that, let me know.  

Tim
minnow.tech


 

Thanks ​@TimBeeston! Makes perfect sense and now my script is working 😁


Reply