SyntaxError: Unexpected token - google apps script

Viewed 33

I created a function with Google apps script, but it is not saved as a syntax error.

There is no problem when tested for each function, but the problem occurs when combined into one function, and there is a syntax error in the last '}'.

I think there is no problem with the typo or format, so please check it.

Thank you.

function createPayment() {
  
  
  var paymentSheet = getSheetById(187490); 
  var paymentExportSheet = getSheetById(5143); 

  
  var ui = SpreadsheetApp.getUi();
  var confirmStart = ui.alert("create payment.", ui.ButtonSet.OK_CANCEL);

  
  if (confirmStart == ui.Button.OK) {
    
    
    var fileName = paymentSheet.getRange(2,2).getValue();
    
    
    var lastRow = paymentExportSheet.getLastRow();
    var lastColumn = paymentExportSheet.getLastColumn();

    var range = paymentExportSheet.getRange(15, 2, lastRow, lastColumn);

    range.clear();

    
    var sourceRange = paymentSheet.getRange(3,1,paymentSheet.getMaxRows(),11);
    var pasteRange = paymentExportSheet.getRange(5,1);
    sourceRange.copyTo(pasteRange,SpreadsheetApp.CopyPasteType.PASTE_VALUES,false);

    
    var maxRow = paymentExportSheet.getMaxRows();
    
    paymentExportSheet.deleteRows(lastRow+1, maxRow - lastRow);
    
    
    var fileName = paymentSheet.getRange(2,2).getValue();

    
    var newSpreadsheet = SpreadsheetApp.create(fileName);
    paymentExportSheet.copyTo(newSpreadsheet);
    
    
    newSpreadsheet.getSheetByName('sheet1').activate();
    newSpreadsheet.deleteActiveSheet();
    
    
    var sourceFile = DriveApp.getFileById(newSpreadsheet.getId());
    DriveApp.getFolderById("1QkjqdRe_dlHur3BnA").addFile(sourceFile);
    
    
    var exportPDF = newSpreadsheet.getBlob().getAs('application/pdf').setName(fileName);
    var createPDF = DriveApp.getFolderById("1QkjqdRe_dlHur3BnA").createFile(exportPDF);
    
    
    createPDF.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
    
    
    sourceFile.setTrashed(true);
    
    
    var ui = SpreadsheetApp.getUi();
    var confirmModal = ui.alert("finish","",ui.ButtonSet.OK);
  }

   
  else {
    var ui = SpreadsheetApp.getUi();
    var confirmModal = ui.alert("cancel","",ui.ButtonSet.OK);
    }
  }    
}
1 Answers

As already pointed out by the user @Palladium02 in the comments, there is an additional curly bracket at the end of the given script.

To help you visualize issues like this in the future, I'd recommend copy/pasting the affected script into a text editor with support for syntax highlighting of your choice other than the Apps Script built-in editor.

Related