We have updated our Terms of Service, Code of Conduct, and Addendum.

How do I assign values to a field whose name is dynamic?

Options

I'm trying to assign a value to a field whose name is a value of another field. I expected __e[fieldName] to work, but it doesn't seem to. I get foo2 , but not foo1

Best Answer

  • Brendan Dalpe
    Brendan Dalpe Posts: 201 mod
    Answer ✓
    Options

    Hey @Eugene Katz , you'll need to use the JavaScript Object.assign operator here in order to set the field name. Because of the dynamic nature of the field name value, it can't be created using the name field column

    You'd end up with this:

    Object.assign(__e, {[__e["fieldName"]]: "bar"})
    

Answers

  • Brendan Dalpe
    Brendan Dalpe Posts: 201 mod
    Answer ✓
    Options

    Hey @Eugene Katz , you'll need to use the JavaScript Object.assign operator here in order to set the field name. Because of the dynamic nature of the field name value, it can't be created using the name field column

    You'd end up with this:

    Object.assign(__e, {[__e["fieldName"]]: "bar"})