Help

Re: "Error: Field cannot accept the provided value" for creating & linking new records

4210 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Airtable_admin
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi all, I’m new to scripting in Airtable and I got a bit confused about my error.

I’m using two variables for the script

  1. projectID which is the ID of the project that is linked to the test record
  2. linkedIndicatorIDs which are the IDs of all the indicators that are linked to the test record

When I run this script it gives an error “Error: Field XXX cannot accept the provided value.” for the project field although via the console.log I see that the correct projectID is being used. I don’t really understand why it doesn’t work for linking the project if it does work for the indicator (I tested succesfully the script without the project linking).

let inputConfig = input.config();


let table = base.getTable('Progress General Indicator 🚫');
let indicators = inputConfig.linkedIndicatorIDs;
let projectID = inputConfig.projectID;

for (let indicator of indicators) {
    console.log(`Adding indicator ${indicator} to the new record.`);
    console.log(`Adding project ${projectID} to the new record.`);
    await table.createRecordsAsync([
    {
        fields: {
            'Projects 🖌': [{id: projectID}],
            'General indicators 🖌': [{id: indicator}],
        },
    }  
    ])

}

Thanks in advance for your help!

7 Replies 7

Can I assume projectID is not the Airtable record ID of the referenced project? If so, pretty sure it won’t work because a linked field (i.e., I assume is Projects) requires a record ID, not an arbitrary field value that serves as a project ID.

Hi Bill, thanks for your help. Actually I believe it is the record ID of the linked project that I’m trying to add there. Also, the console is saying " 1. “Adding project recrKig6PwXmDRblB to the new record.”"

2screencap
1screencap

That looks right. And you’re certain the field Projects is a link field?

Hi Bill, thanks for getting back to me. Yes, I’m certain.

Luckily, I found the issue, namely, projectID was a vector of strings here (with only 1 element). So when I printed it in the console I couldn’t understand the issue.

The issue is now solved by selecting the first element in the array (projectID2):


let inputConfig = input.config();

let table = base.getTable('Progress General Indicator 🚫');
let projectsTable = base.getTable('Projects 🖌');

let indicators = inputConfig.linkedIndicatorIDs;
let projectID = inputConfig.projectID;
let projectID2 = projectID[0];
let recordID = inputConfig.recordID;
let linkedIndicators = inputConfig.linkedIndicators;

/*Create new records (children)*/
for (let indicator of indicators) {
    console.log(`Adding indicator ${indicator} to the new record.`);
    console.log(`Adding project ${projectID2} to the new record.`);

    let newRecordId = await table.createRecordsAsync([
        {
            fields: {
                'Projects 🖌': [{id: projectID2}],
                'General indicators 🖌': [{id: indicator}]
            }
        }
    ])

} 

Thanks a lot for your help!

@Pello_Mugica_Gonzale , are you the same person as @Airtable_admin ?

Or are there two people with similar issues?

Woops, same person indeed. Didn’t realize I switched accounts!

Glad you got it fixed.

Proof that sharing the actual code at the outset might have saved some anguish and time. :winking_face: