0
votes

I'm trying to follow this guide (Never programed before):

https://www.groovypost.com/howto/google-sheets-send-email-based-on-cell-value/

But It keeps giving me the error:

Exception: The parameters (number[],String,String) don't match the method signature for MailApp.sendEmail. sendEmail @ Send Email.gs:8

For what I understand this means the email value is taking as a number. But I have no idea how to solve this.

function sendEmail() {
// Fetch the email address
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Client Input").getRange("D2");
var emailAddress = emailRange.getValues();
// Send Alert Email.
var message = 'Please go to your Issues Tracker for more information'; // Second column
var subject = ' Notification Action Required';
MailApp.sendEmail(emailAddress, subject, message);  
}
1
It's just telling you that you sending an array to the recipient instead of a string. emailRange.getValues() returns a two dimensional array - Cooper
Tell us more about the range and we can suggest an alternative.minimal reproducible example - Cooper
if you intend it two be an array of recipients you might you might get away with emailRange.getValues().flat().join(','); - Cooper

1 Answers

1
votes

Since emailRange.getValues() returns a 2D array you need to reference the actual string value by its indices, which in this case, [0][0] as the array has only one value.

var emailAddress = emailRange.getValues()[0][0];

Or if you intend to use one and only one email address, just use:

var emailAddress = emailRange.getValue();

References:

Class Range | getValues()

JavaScript Arrays