Serge insas
Serge insas

Reputation: 46794

syntax error in GAS script editor

I have an error in the following code and I can't find why...

Using UiApp I define a couple of ListBox like this in a for loop

   var critGlist = app.createListBox().setName('critGlist'+n).setId('critGlist'+n).addChangeHandler(refreshGHandler).addChangeHandler(cHandlerG).setTag(listItem[n]);

I added a TAG to be able to retrieve a value in the handler function because when I add items to this list I do it like this :

   for(var c=0;c<listItem[n].length;++c){
      critGlist.addItem(listItem[n][c],c);// the returned value is c, the value shown is listItem[n][c] 
    }

Then in my handler function I retrieve the value c that is the index of an element of the array listItem[n]

Since I stored a stringified value of this array as a tag I have to retrieve the tag first and then using the index I get the desired value...

That's where it becomes problematic !

I tried the 3 following codes :

    var idx = Number(e.parameter['critGlist'+c]);// this works and I get the index

    var item = e.parameter.critGlist0_tag.split(',')[idx];// this also works for a fixed index (0 here) but I need to use it in a for loop so I tried the code below

    var item = e.parameter['critGlist'+c]_tag.split(',')[idx];// this generates an syntax error 
// error message :"Signe ; manquant avant l'instruction. (ligne 129, fichier "calculatrice Global")"
// which means : missing ; before statement (line 129...

Am I missing something obvious ? How should I write it differently ?

Obviously it is the underscore that is not accepted... but how could I not use it ?

Well, I have a few other possibilities to get the result I want (using a hidden widget for example or some other temporary storage of even let the listBox return the value instead of the index) but still I'd like to know why this syntax is wrong ...

I'm not asking for a different code (as mentioned before there are a lot of other ways to go) , just some explanation about what is wrong in this code and this #!##å»ÛÁØ underscore ;)

Upvotes: 0

Views: 268

Answers (1)

Abhishek Ram
Abhishek Ram

Reputation: 324

You will need to put the whole property within the brackets as below

var item = e.parameter['critGlist'+c+'_tag'].split(',')[idx];// this generates an syntax error 

Upvotes: 1

Related Questions