Help

Re: Automation script update linked record - Help please?

Solved
Jump to Solution
1499 0
cancel
Showing results for 
Search instead for 
Did you mean: 
John_Young1
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi,

I am trying to adapt/modify scripts that i have found within these forums in order to update a linked field with a recordID defined as an input variable.

I am very limited in knowledge with scripting, through trial and error i have been able to modify and update a single line text field and a single select. I have also managed to clear the cell through a previous failed attempt.

Can anyone help me understand where im going wrong?

Full Script Here.

let config =input.config()

let records = config.step2Records

let drop = config.drops

console.log(drop)

let table = base.getTable(“All Drops”);

for (let record of records) {

await table.updateRecordAsync(record, {

        "Collection From": [{id: drop}],

    })        

}

I have read through all posts similar looking but i am at a loss. I would like the answer but also any reference to learning material would be great.

Many thanks,

1 Solution

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

Thank you for the screen shot. Look carefully at the right third of the screen.

The Script input section tells you the script input values, but it obscures the data types of those values.

Look carefully at the output of the console.log statement. This result shows the data type of the variable being logged. The value of drop looks like a record id, but it is not. It is an array with one record id. You need to get that first element of the array to get the actual record id.

See Solution in Thread

6 Replies 6

Welcome to the Airtable community!

Congrats on working on learning coding. It can be a frustrating but rewarding process.

Can you post screen captures that show what your script produces? Can you say what your script actually does and compare that with what you want to happen?

Is the script throwing an error without updating any records! Does it update some records, but not all?

I also suspect that the records variable does not contain the data type you expect. Try logging the value and look at its data type. It is probably a string, where you want an array. Look into how to split a string into an array.

John_Young1
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi @kuovonne,

Many thanks for your reply.

Screenshot of script, inputs and error below:

c28bbf656250b99073102a6db88bf9b9ae531395

Interestingly, when the input “drops” is not the recordId but the record name,

let config =input.config()
let records = config.step2Records
let drop = config.drops
console.log(drop[0])
let table = base.getTable(“All Drops”);
for (let record of records) {
await table.updateRecordAsync(record, {
“Test”: drop[0],
“Update Load”: true,
})
}

I have managed to make the above script work by adapting the script to update both the records with the record name stored as config.drop in a text field as well as update a checkbox to true on both, that will then work as part of a seperate conditional automation found in drop.

I have started with Sololearn and have gotten to this point through mostly through what i have found on here, a great deal of trial and error and a lot of console.log calls placed strategically to try and better understand whats going on.

Using the [0] i have been able to empty the linked field, but this has only emptied the value, not updated as expected.

I am however, still looking to understand how i can make this happen and what i am doing wrong?

Thanks again,

John

kuovonne
18 - Pluto
18 - Pluto

Thank you for the screen shot. Look carefully at the right third of the screen.

The Script input section tells you the script input values, but it obscures the data types of those values.

Look carefully at the output of the console.log statement. This result shows the data type of the variable being logged. The value of drop looks like a record id, but it is not. It is an array with one record id. You need to get that first element of the array to get the actual record id.

Wow! You should bill your clients separately for patience. This is a fine example of bedside manner that many of us can learn from.

  • Requirements: $150
  • Development: $450
  • Patience, kindness, sharing: $1500

@kuovonne

I got there in the end.

Thank you very much for your advice.

I have marked your answer as my solution.

So glad you got there in the end.

When answering questions on these forums for free, it is hard to pick the right amount of advice that will enable new script writers to help themselves without giving away the answer completely. (And sometimes it isn’t even possible to be sure of an answer from only a screen shot. Plus, I tend to save complete code for paying clients.)