0

Hi I have a syntax error on a GoogleScript. this is my first script ever so I'm not really sure why is not working. The idea is to pick up information from a google sheet and create a label from a doc template and storage it in a folder

function readSheet() {

const labelFolder = DriveApp.getFolderById("1NTnJgjCewcFcrtMsl5DtRgrvFUNCdsvt"); 

const docFile = DriveApp.getFileById("1pRy9BLDuDka7-9PKnHGgO1AtgpoWIY45t7ypVhXXM8I");

const sheet = SpreadsheetApp.gettActiveSpreadSheet().getSheetByName("test");

const data = sheet.getRange(2,1,sheet.getLastRow()-1,10).getValues();

  data.forEach(row => {

      shippinglabels(row [5],row [6],row [8],docFile,labelFolder);
});

}

function shippinglabels(user,address,package,docFile,labelFolder) {
   
  
  const labelFile = docFile.makeCopy(labelFolder);

  const tempDocFile = DocumentApp.openById(labelFile.getId());

  const body = tempDocFile.getBody();

  body.replaceText("{user}", user);

  body.replaceText("{address}", address);

  body.replaceText("{package}", package);

  tempDocFile.setName(user);

  tempDocFile.saveAndClose(); 
  

     
    }

Thanks

3
  • How do I ask a good question? Commented Jul 17, 2020 at 7:22
  • Where is the syntax error? Commented Jul 17, 2020 at 7:22
  • 1
    Are you using v8 runtime? It's defaulted to stable Commented Jul 17, 2020 at 7:37

2 Answers 2

1

Please modify as follows and test it again.

From:

const sheet = SpreadsheetApp.gettActiveSpreadSheet().getSheetByName("test");

To:

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("test");
  • In this case, gettActiveSpreadSheet() is getActiveSpreadsheet().
  • I think that after above modification was reflected to your script, when the folder ID, Google Document ID and the values from Google Spreadsheet are correct, no error occurs. When other error occurred, can you provide the detail information about it? I would like to confirm it.

Reference:

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the comment, modify what you said but still the same error as before. When I try to save the script , doesn't save and highlight "data.forEach(row => {" and said as error Syntax error. (line 14, file "Test"). That is the line for the forEach.
@Aloe Francisco Thank you for replying. In your case, in addition of above modification, I think that you doesn't enable V8 runtime as Thum Choon Tat have already said. So how about enabling V8 runtime at the script editor and test it again?
1

I change the forEach form this:

data.forEach(row => {
    
          shippinglabels(row [5],row [6],row [8],docFile,labelFolder);
    });

To this:

    data.forEach(function(row) {
      shippinglabels(row [5],row [6],row [8],docFile,labelFolder);
});

and did the job.

Thanks for the help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.