When using the following code in Google Apps Script, the function runs properly, but throws an error:
Invalid email: undefined (line 6)
Here is the code:
function emailStockPrice(symbol, email) {
Logger.log('Emailing stock price of ' + symbol + ' to ' + email);
var info = FinanceApp.getStockInfo(symbol);
Logger.log(info);
var price = info['price'];
MailApp.sendEmail(email,
'Price for: ' + symbol,
price);
}
emailStockPrice("PRXL","james.shook@gmail.com");
If testing, please use your own email in the function :). Any idea why it says that “email” is undefined?
How are you running the function? Are you running this from the script editor by choosing emailStockPrice and clicking run? If so, then email and symbol will both be undefined, since the function is expecting those values to be passed in.
Instead, this function is meant to be called from within some other function. Try something like this:
and then run the test function.