Skip to main content
1-Visitor
February 9, 2019
Solved

Dynamic Field for AddRow function

  • February 9, 2019
  • 1 reply
  • 2642 views
Hey everyone. I need help to figure out how to code a dynamic field name in a params clause. Below is the example of code.

AttTable.AddRow({
DYNAMICNAMEHERE: table.rows[0].DYNAMICNAMEHERE})

For the DYNAMICNAMEHERE I am declaring the variable value farther up in the code and referencing it as the variable name in those two sections but it isn’t working.
Best answer by CarlesColl

If I understand well what you want to do, you should do something like:

var dynamicNameHere = "myCustomFieldName";
var newRow = {};
newRow[dynamicNameHere] = table.rows[0][dynamicNameHere];
AttTable.AddRow(newRow);

1 reply

1-Visitor
February 11, 2019

If I understand well what you want to do, you should do something like:

var dynamicNameHere = "myCustomFieldName";
var newRow = {};
newRow[dynamicNameHere] = table.rows[0][dynamicNameHere];
AttTable.AddRow(newRow);
1-Visitor
February 11, 2019

Thank you for the response! How would it look if I was also adding values for known table headers in that same add row function? Would I just tack on to that string "newRow"?

1-Visitor
February 12, 2019

New row it's a Javascript object not a String, and yes you can add as many fields as you want :

 

var newRow = { myField1: "myFieldValue1", myField2: 12.0 };
newRow[dynamicField1] = "dynamicFieldValue1";
newRow[dynamicField2] = "dynamicFieldValue2";
newRow["thirdDynamicField"] = 10.3;