Skip to main content
Solved

Using a variable for field name in updateRecordAsync method

  • August 12, 2022
  • 2 replies
  • 52 views

Forum|alt.badge.img+2

Hi there!

I’m not a developer but I trying to write a script.
Please tell me if is possible to use a variable to define the field name inside updateRecordAsync method.

await table.updateRecordAsync(record, {"Phone": value})

the method accepts variables for “record” and for field “value”

but I want to use a variable for “Phone” (without quote marks) like the example below:

let fieldName = "Phone";
await table.updateRecordAsync(record, {fieldName: value});

I want to let users set up fieldName using input.config

Please help. :pray:

Best answer by Alexey_Gusev

Hi,

use such syntax for that:
await table.updateRecordAsync(record, {[fieldName]: value});

2 replies

Alexey_Gusev
Forum|alt.badge.img+25
  • Brainy
  • 1261 replies
  • Answer
  • August 12, 2022

Hi,

use such syntax for that:
await table.updateRecordAsync(record, {[fieldName]: value});


Forum|alt.badge.img+2
  • Author
  • New Participant
  • 2 replies
  • August 12, 2022

Hi,

use such syntax for that:
await table.updateRecordAsync(record, {[fieldName]: value});


Thanks, Alexey! I appreciate it