Home > Blockchain >  How to get file ID to send mails from GoogleSheets/Script
How to get file ID to send mails from GoogleSheets/Script

Time:11-17

I'm new to coding and i'm having issues with a code where i keep getting "Error Syntaxis: Missing ) after argument

This is my current code:

    function myFunction(){
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet('Form Responses 1');
  const url = sheet.getRange().getValues();
  url.forEach(function(row,index){
    if (index === 0) return;
    if (row[19]) return;
  const idFile = url.match(/[-w]{25,}/);
  const file = DriveApp.getFileById(idFile)
  const blob = file.getAs(MimeType.PDF)

  var message = 'Thanks for your interest this will be the first step'
  var mail = row[2]
  var team = row[8]
GmailApp.sendEmail(mail,team,"Subject",message,{attachments: [blob]})

This is my second script, the first one i built it to create PDF for each new google form entry and in column 19 the PDF link is written. The idea is that after that PDF linked is created it takes the file ID and then sends it automatically to the person that filled the form with CC to my team if there is no link created then it should not send it.

But i have researched and i honestly don't know much to identify my error, i hope anyone can help me i would appreciate it. Either not by giving the answer but help in any form would be appreciated!

CodePudding user response:

Missing parenthesis after the arrow function see comment below

function myFunction() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet('Form Responses 1');
  const url = sheet.getRange().getValues();
  url.forEach(function (row, index) {
    if (index === 0) return;
    if (row[19]) return;
    const idFile = url.match(/[-w]{25,}/);
    const file = DriveApp.getFileById(idFile)
    const blob = file.getAs(MimeType.PDF)

    var message = 'Thanks for your interest this will be the first step'
    var mail = row[2]
    var team = row[8]
    GmailApp.sendEmail(mail, team, "Subject", message, { attachments: [blob] })
  });//your missing the parenthesis here after the arrow function
 }

CodePudding user response:

You're missing several closing brackets and parenthesis.

function myFunction(){
    const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet('Form Responses 1');
    const url = sheet.getRange().getValues();
    url.forEach(function(row,index){
        if (index === 0) return;
        if (row[19]) return;
        const idFile = url.match(/[-w]{25,}/);
        const file = DriveApp.getFileById(idFile);
        const blob = file.getAs(MimeType.PDF);

        var message = 'Thanks for your interest this will be the first step';
        var mail = row[2];
        var team = row[8];
        GmailApp.sendEmail(mail,team,"Subject",message,{attachments: [blob]});
    });
}
  • Related