Using variable in field of update record?

Hey I’m trying to update a few fields on a record. Same process each time. So I have a for loop that goes through an array with a combo of the field I want to update and the values to put in.

A basic version looks like this:

Array = [{“Field”:“field 1”, “value 1”: “something”}, {“Field”:“field 2”, “value 1”: “something”}]

For item in array do:

Some processing

Table.updateRecordAsync(RecordID, {"${variable string with field name}": another variable value})

However I can’t get the field

"${variable string with field name}"

to take a variable no matter how I set it up. I have tried every combo of ’ " { [ around the variable. And tried constructing the variable separate as a full string to put in but to no avail.

Is it possible to use a variable in the field?
How could I do this?

Many thanks.

I predict @kuovonne will beat me to answering this question so I think I’ll just have another bite of my cinnamini. :wink:

(Honestly, I spent more time thinking about how to spell “cinnamini” than I did on the question.)

You need to use a backtic character ` instead of a single or double quotes.

Really? So you decide to not answer at all? Even though you did answer first?

I just happened to decide to check the forums because I needed a break from sewing. I’m on a tiny 4” phone screen on a phone that was obsolete when I got it used five years ago. Typing the whole line of code is too hard and I don’t even have a real keyboard in front of me so I can’t say where the key is located. And the screen is too small to see a preview of what I type so I wasn’t sure if I should put backtics around my backtic to make it show up in the code font.

Enjoy your cinnamini, which I had to type multiple times to get autocorrect to stop autocorrecting. :crazy_face:

P.S. thanks for the laugh and the excuse to let me rant about the difficulties in posting from my phone. I haven’t decided if I should invest in a newer phone or stop checking the forums so often.

Shoot now that I re-read the question, it looks like you are trying to use a variable as an object key, not insert a variable in a string. In that case, try something like this:

Table.updateRecordAsync(RecordID, { [variableForFieldName] : variableForValue})

Since the variable holds a string, you need to put the variable in square brackets to use the value of the variable as the field name.

The ${variable} text distracted me from your real issue, leading me down an different mental path. When you use ${} syntax, you have to use backtics.

Apologies for the briefness of the reply. I’m on a small phone screen and just taking a break from sewing. It is all to easy to grasp at one small part of the issue and not see the big picture.

1 Like

I recommend both. [additional random characters to make a post]

thank you @kuovonne [ ] are the answer. best of luck with the sewing.