Help

Re: Updating a field when I don't know the name

622 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Jeff_Blankenbur
5 - Automation Enthusiast
5 - Automation Enthusiast

I have 20 fields in my table that are named ACH001, ACH002, ACH003, etc. (They’re achievements for a game.)

I want to update a specific field when a user completes the achievement, but I don’t know which one they’re completing until I’m ready to make the update call to the database. So, I’m creating a variable called “fieldName” that contains the name of the field. This doesn’t seem to work, however. I get an UNKNOWN_FIELD_NAME error. Error 422. Anyone have any tips on how I should approach this one?

var fieldName = getFieldName(achievementId);
var airtable = await new Airtable({apiKey: process.env.airtable_key}).base(“appx5AkeU3qgwlYDn”);
airtable(‘User’).update(UserRecord.RecordId, {
fieldName: Date.now()
}, function(err, record) {
if (err) { console.error(err); return; }
});

1 Reply 1
Jeff_Blankenbur
5 - Automation Enthusiast
5 - Automation Enthusiast

Figured it out. Just needed to wrap fieldName in brackets, like this:

[fieldName]: Date.now()