我想在用户点击按钮时发送电子邮件通知。该按钮将调用 sendEmail(widget)
函数并调用客户端脚本,如下所示:
function sendEmail(widget){
var item = widget.datasource.item;
google.script.run
.withFailureHandler(function(error) {
console.text = error.message;
})
.withSuccessHandler(function(result) {
console.text = 'succeed';
})
.sendEmails(item);
}
然后它将在item
上传递数据源并从服务器脚本调用sendEmails(item)
函数,如下所示:
function sendEmails(item){
var to = item.OwnerEmail;
var subject = 'Please Review';
var body = 'hello<br/>my name is Muhammad Alif bin Azali';
MailApp.sendEmail({
to: to,
subject: subject,
htmlBody: body,
noReply: true
});
}
但是当我点击按钮时却出现了以下错误。有帮助吗?
最佳答案
不幸的是,您不能将任何您想要的参数作为参数传递给您的服务器函数。与服务器的通信有一些 limitations :
...most types are legal, but not Date, Function, or DOM element...
...objects that create circular references will also fail...
App Maker 的记录肯定违反了这些限制。
有不同的策略来处理这个限制,其中之一是将记录的键作为函数的参数传递。
// Client script
function sendEmail(widget) {
var item = widget.datasource.item;
google.script.run
...
.sendEmails(item._key);
}
// Server script
function sendEmails(itemKey) {
var item = app.models.MyModel.getRecord(itemKey);
...
}
关于javascript - 在 Google AppMaker 中发送电子邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50479987/