Help

Re: Automation Scripting Error - Field cannot accept provided value

6439 6
cancel
Showing results for 
Search instead for 
Did you mean: 
Megan_Ecclesto1
6 - Interface Innovator
6 - Interface Innovator

Not sure why I keep getting an error message when I try to automate this script:
Error
I just need the first 5 digits of the Project code pasted into the 5 digit (linked) column. If it doesn’t already exist, it needs to create a new record.
Help?

22 Replies 22

When writing values to a linked record field in a script (either scripting app or a automation script action) you cannot “paste” in the desired text the way you can with the user interface. To set the value for a linked record, see the write format for a linked record.

Between the code that @Justin_Barrett wrote and the code that I wrote, you should be able to get the record id and write it in the correct format. However, there could still be problems elsewhere. For example. we don’t know the field name or field type of the field in the short table, and either could be causing problems.

It is also surprising that you are getting a five digit code from the line fullCode.substring(0,4) as I would expect to get only four digits from that line.

It would be easier to help you if you could include screen captures of your data (including column headings), your code, and the error messages from scrpting app.

So I played with it some more and got it to write in the 5 digit code value. ( added the output.text to ensure pulling the first 5 digits in a string)

However, it only does it for the first record. How can I fix it to run through all records?

fiveDigitCode gridviewfiveDigitCode
(Or - if this is automated to trigger on a record creation on the Long Code tab, will it not matter?

Thanks again for all your help!

Congrats on getting the script to work as a script app. If you convert the script to an automation script action, the script does not need to run through all records. Because automations are triggered by a specific record, each automation run will only affect that one record.

If I wanted to leave it as a Scripting App, how would I have it run through all the records?

To have the script run through all the records in a view of a table, you need to get all the records in the view, and then loop through them.

let table = base.getTable("Table Name")
let view = table.getView("View Name")
let queryResults = await view.selectRecordsAsync()
for (let record of queryResults.records) {
  // do stuff with your record here
  // either directly 
  // or by calling a function that acts on one record
}
Giorgio_Bazziga
6 - Interface Innovator
6 - Interface Innovator

I am having the same issue and there does not seem to be a solution. Who would have thought updating values would be so difficult.

What is the value that a linked record is expecting?

Nicholas_Ventur
4 - Data Explorer
4 - Data Explorer

I’m having a similar issue.
the list is > 10 items, and yet the loop completes with “updateRecordAsync” writing only a single element, the last element in the list.

for (let thisWord of list_of_unique_feeling_words_in_this_transcript) {
    let feelingsTableRecord = feelingsTableQuery.records.filter(record => record.getCellValue("Feeling Word") === thisWord.toString());
    await memberTable.updateRecordAsync(thisMemberRecordID[0], {
        "Overall Feelings Words Used": [...thisMemberRecordID[0].getCellValue("Overall Feelings Words Used"),{id: feelingsTableRecord[0].id}]
    });
};

I don’t see this sentiment stated here often, but Airtable’s docs, as detailed as they are, are a terrible place to actually learn JavaScript.

Every functionality of the platform is well-chronicled, sure, but in order to read the notation, you’re expected to have a solid grasp of JS context, scope, object-oriented programming, ternary operators, IP/TCP specification (how many “I can’t write a fetch() request, hurr durr” posts are we getting here daily?), JSON standard, immutability, and I’m probably forgetting a bunch of other stuff right now.

I’m not saying this to discourage you @Nicholas_Venturino but to encourage you to get your JS fundamentals elsewhere; Mozilla’s docs are an excellent place to start, as evidenced by how eager Airtable’s PR reps are to link to them, whatever the occasion.

Once you become more comfortable with the language, I’d suggest reading ECMA-262 directly but that’s probably too much right now.

As for how to bend linked record fields to your will, Airtable expects the following format:

let recordToUpdate = "recxyzxyxzxyz" //this is supposed to be a record.id
let recordsToLink = [{id:"recQdBXPuNonFOa4X"},{id:"recQdpxPuOonFOh4X"}]
//assuming your linked record field is called Notes and is located in a table called Table 1
await base.getTable("Table 1").updateRecordAsync(
    recordToUpdate ,{
        "Notes": recordsToLink 
    });

Note that this setup will overwritte the linked record field, so if you want to add to its existing contents, you’ll want to make sure the recordsToLink array includes those contents before executing the aforementioned lines.

You should be able to do that by querying the record to update, then doing something in the vein of:

recordsToLink.push(yourQueriedRecord.getCellValue("Notes"))

Again, try to work on your fundamentals in a low-stress environment or otherwise none of this will make too much sense and copy-pasted code is a nightmare to debug, assuming what I typed here even works lol.

Very true. Airtable’s scripting documentation is a great place to learn Airtable’s scripting API, but a poor place to start if you do not yet know JavaScript fundamentals. New script writers do not need to know quite as much as Dominik lists in his post, but they do need to know enough JavaScript to be able to read and understand the examples in the Airtable scripting documentation before the scripting documentation will be of use.

Just to close the loop for anyone else looking at this issue. I was able to get it working by creating a new array and using two different spread operators.

    let arr = []
    for (let w of list_of_unique_feeling_words_in_this_transcript){
    let feelingsTableRecords =  feelingsTableQuery.records.filter(record => record.getCellValue("Feeling Word") === w.toString())
    arr.push(feelingsTableRecords[0])
    }

    if (members_feelings_records != null ){
        await memberTable.updateRecordAsync(thisMemberRecordID[0], {
            "Overall Feelings Words Used": [...thisMemberRecordID[0].getCellValue("Overall Feelings Words Used"),...arr]
        });
    }

It’s still unclear to me why my previous code block doesn’t run as expected. I’m guessing it’s something to do with “updateRecordAsync” being an async function.