0

I would like to add data to my EmailTemplate in the for loop. Unfortunately this does not work as expected. I get the error code "Invalid assignment left-hand side." every time. I want the counter to go up after each run and adapt to the temp file.

Here is the "problem Code". Without it the Script runs perfectly.

var emailTemp = HtmlService.createTemplateFromFile("template"); // Access to the HTML document       
var z = 1;
    var softindexlen = softwareindex.length;
    for(var b = 0; b<softindexlen; b++){
      if (b<6){
        emailTemp.PCCI+z = computerarray[softwareindex[b][0]];
        emailTemp.PCEquip+z = computerarray[softwareindex[b][7]];
        emailTemp.PCassetname+z = computerarray[softwareindex[b][1]];
        emailTemp.PCassettag+z = computerarray[softwareindex[b][4]];
        emailTemp.PCserial+z = computerarray[softwareindex[b][9]];
        emailTemp.PCmanufac+z = computerarray[softwareindex[b][5]];
        emailTemp.PCmodel+z = computerarray[softwareindex[b][6]];
        z++;
      }else{
        emailTemp.pcnotification = pcnotification;
        break;

      }
    }

Hopefully someone of you can help me ! (And sorry if the header isn't the best )

Many thanks in advance!

AirHunter
  • 5
  • 5
  • 1
    Does this answer your question? [Is it possible to add dynamically named properties to JavaScript object?](https://stackoverflow.com/questions/1184123/is-it-possible-to-add-dynamically-named-properties-to-javascript-object) – tehhowch Nov 15 '19 at 12:23

2 Answers2

1

Use bracket notation:

emailTemp["PCCI"+z] = /*some value*/
TheMaster
  • 45,448
  • 6
  • 62
  • 85
1

Like @TheMaster said, you have to use the bracket notation to access properties (what you access with a.b) with dynamic names.

To do this, you can use the nature of Apps Script to access the properties by name with [name].

Since your names include a dynamic number, try accessing the properties like this:

emailTemp["PCCI"+z] = value;
ZektorH
  • 2,680
  • 1
  • 7
  • 20