HELP - Syntax error: SyntaxError: Unexpected string

1,461 views
Skip to first unread message

Ryuya

unread,
Jun 21, 2022, 3:53:12 AM6/21/22
to Google Apps Script Community
Hi there,

I have a concern on the following script.

Every time I attempted to save, it says "Syntax error: SyntaxError: Unexpected string line: 12 file: Code.gs". Seemingly, there should be an error on line 12 that I don't know why.

What I would like to do:
- Merge some cells into one then paste it on a cell with customized format.

How I will run the script;
- Every time I set up start Row and end Row by inserting row number manually onto the certain cells then run the script.

Hope you can help me with this.
Thank you in advance for your assistance!

スクリーンショット 2022-06-21 16.47.25.png

Clark Lind

unread,
Jun 21, 2022, 7:09:35 AM6/21/22
to Google Apps Script Community
Try creating the whole string first before putting it into an array. In fact, I don't think you need it in an array since you are putting it in an array when you use setValue([text]).

R Tichy

unread,
Jun 21, 2022, 7:54:47 AM6/21/22
to Google Apps Script Community
Either that, or put a comma at the end of each line within the array brackets, because you are trying to make an array.

Ryuya

unread,
Jun 21, 2022, 9:14:34 PM6/21/22
to Google Apps Script Community
Hi, thank you for your support.

I am just wondering if you could specifically elaborate by saying "try create the whole string" .

That would be much appreciated.

R Tichy

unread,
Jun 21, 2022, 10:19:21 PM6/21/22
to Google Apps Script Community
If you are trying to make a single piece of text, then lines  11 - 15 need a '+' after the '\n', so they look like this "blah blah :" + data[i] + "\n" +  <=== this 'plus sign' is missing from your code

The next question is "why" do you need the brackets [  ] that start on line 10 and end on 17?  The brackets mean you are trying to create an array element?

But when you use the value in line 19, you put it inside another array with a new set of brackets, when you do the setValue().

Clark Lind

unread,
Jun 23, 2022, 8:08:55 AM6/23/22
to Google Apps Script Community
You could also use some modern syntax to make things really easy for yourself using backticks and templated variables:

let text = `Join Date: ${dataValues[i][0]}
Full Name (Nickname): ${dataValues[i][1]}
Team: ${dataValues[i][2]}
Role: ${dataValues[i][3]}
Hobby: ${dataValues[i][4]}
Message: ${dataValues[i][5]}`
Reply all
Reply to author
Forward
0 new messages