Help

Re: New Script: Same Table Linked Records Backlinks

2974 8
cancel
Showing results for 
Search instead for 
Did you mean: 
openside
10 - Mercury
10 - Mercury

Explainer Video:

Base:

Code:

64 Replies 64

Took another look at that error, it seems like your loop isn’t terminating correctly, try changing line 116 to

if(foundItem>1)

otherwise, on its last check, the code goes

  • foundItem.length is 0 - true
  • let’s go splice our obviously empty array
  • uh, oh, something went wrong, boss

Using the length instead of a direct check for the loop is a smart move, mind you, because it’s way faster than accessing the whole Object directly and it’s likely that the code will re-evaluate line 116 a bunch of times so the performance gain could be significant, depending on the base. The drawback here was a bit of a loss on the readability front but hopefully this gets it working.

Thanks. I’ve tried changing line 116. I get the following error:

ERROR
SyntaxError: Unexpected token ‘}’
on line 1
at a on line 1
at Generator._invoke on line 1
at Generator.F.forEach.u. [as next] on line 1
at u on line 1
at o on line 1
on line 1
on line 1

Which makes me think there is a bracket out of place, but I’m not sure where that bracket is.

Could you share a screenshot of the change that you made to line 116, including as much of the code that follows it as possible?

Thanks! Here is a screenshot.

Screen Shot 2021-07-07 at 7.15.50 PM
I re-added the code so line 116 is now line 120.

Let me know if there is anything else that would be helpful to share.

I think that there may be some confusion here. There have been multiple scripts shared in this thread, and the tip from @Dominik_Bosnjak is related to line 116 in the latter of the two—the post by @Theo_Michel in September of 2020—which looks like this:

    if(foundItem >= 0) {

The script snippet in the screenshot that you shared didn’t come from that script, so the change that you made actually introduces a bug because it’s not related to the rest of the code.

Which script above did you use as the basis for your setup?

Thanks. I was not aware there were two scripts on the page. I am using the script at the top of the page.

Do you think it would be better to use the 2nd one?

Could you clarify the difference between the two?

Wow, good call @Justin_Barrett , I was debugging the wrong thing weeks apart.

I’ll take another look in a bit, but as far as merit goes, the second script utilizes recursion, takes advantage of prototypal inheritance, and is nicely formatted to top it off so that I can actually see what’s going on even through a Friday migraine.

Basically, some of JavaScript’s biggest strengths utilized in 130 lines of code.

The other effort, the one you’re trying to get to work, apparently, is tenacious, but clearly written by someone less experienced; possibly someone who only picked up programming with JavaScript. Just my 2 cents on

How often do you need this to run? And are you sure you want it to be an automation? A base with a couple thousand records in it and you’re one missing semicolon away from filling your monthly automation quota within hours. Unless you’re only running a single automation per base and that sole isn’t in charge of both creation and deletion, that 100k cap is never too safe.

And you know, we had a lot of missing semicolons here by now haha.

huh… A Masters in Computer Science, 20+ years of professional programming across atleast 5 different languages, built systems supporting millions of users, built one of the more popular Airtable products in their ecosystem, and still have a long ways to go to catch up to your skills. Thanks for keeping me humble Dominik, I always need the reminder :winking_face:

Nah, we’re about even if I also count my years of experience in eating my own words, that “I’m an idiot” feeling is quintessential programming imo, more than any technology or trend can ever hope to be. And I’m yet to encounter someone who codes – maybe for a living, maybe just because, emphasis on the present tense – and is in need of a humbling haha.

Case in point: you not automatically assuming I meant the other person because my comment doesn’t make sense otherwise.

Whereas in reality, it’s just an indexing issue . :joy:

And if Theo(dore?) frequents these forums, I’m now really curious how accurate I’ve been overall.

Scripting has undergone a lot of changes since this thread was started.

I decided to write a new version of the script to take advantage of some new features, such as script settings, that lets the script remember the table and fields without having to touch the code.

This version has a few differences from the original and is entirely my own code, although aspects of the algorithm are similar.

  • uses script settings for setting table & fields (which did not exist before)
  • works on only one table, not multiple tables
  • does not allow limiting records to a view
  • various speed improvements and error checking

This script is best used as a batch update when first setting up back links. I also have a matching automation script for when either the link or the backlink is updated, without needing to store previous versions of links. If you are interested in the automation script, please book an appointment with me.