Google表格的脚本(自动电子邮件功能) [英] Script for Google sheets (auto email function)

查看:164
本文介绍了Google表格的脚本(自动电子邮件功能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google表格脚本

Google Sheets Script

当 A列标记为已完成时,我需要生成自动电子邮件回复。发送给它的电子邮件地址在 I列中,电子邮件的主题必须在 H列中为数据,而电子邮件的正文对于所有发送的电子邮件都是通用的。这是每个行所特有的。

I need to generate an auto email reply when Column "A" is marked "Completed". The email address to send this to is in Column "I" and subject of the email needs to be data in Column "H" while the body of the email will be generic for all emails sent. This is all specific to each Row.

我正在运行多个脚本,用于隐藏行等,但是没有那么复杂。

I have multiple scripts running, for hiding rows etc, but nothing this complex.

所有数据都从Google Forms发送到电子表格,并且需要包含所有行

All data is sent in to spreadsheet from Google Forms, and will need to encompass all rows

任何帮助将不胜感激。

推荐答案

我为此创建了一个脚本,除了它没有复选框。通过添加.getdisplayvalue

I created a script for something similar to this, except it runs off of check boxes. You could easily edit this code to have the email recipient variable to point to a value in a column by adding a .getdisplayvalue

您可以轻松地编辑此代码,以使电子邮件收件人变量指向列中的值。我基本上像脚本一样使用它触发器,因此我不会用它代替您拥有的进度列,而是添加一列供他们检查何时完成编辑行。

How I used it is basically just as a script trigger, so I wouldn't have it replace the "progress" column you have, but to add a column for them to check when they're done editing the row.

侧面注意:该脚本在警报上单击是,我想发送电子邮件后,有意将复选框重新设置为默认值,否则该脚本将

没有看到您的Google表格或当前代码/此代码已插入,我将完全无法帮助您实现。让我知道是否有帮助。

Without seeing your Google Sheet or current code/this code inserted, I wouldn't be able to help you implement at all. Let me know if this helps.

/*

 A function to:
 
* After clicking a checkbox, auto prompt a yes/no box
* Upon "yes", copies that row from the source sheet to a destination sheet
* send an e-mail based on that new row's data
 
 I reccomend protecting the response sheet and hiding it, as well as protecting the check box column to give edit access to only those you want to be able to send e-mails.
 
 NOTES:
 
 *It is important that the headers on your source sheet match your destination sheet.

* You have to run the script from the editor first to accept permissions for the emailapp and driveapp

* you need to set up a project trigger (edit/current project triggers) for the source sheet, on spreadsheet, on edit.

*The email will come from the owner of the google sheet and owner of the script project. (the person who reviews and accepts permissions)
 MAKE SURE you are the owner of the sheet, that you are putting the code into the editor, and that you're okay with the e-mail coming from and replying to your email address.


*/


function EmailNotification(e) {

var ui = SpreadsheetApp.getUi();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Assets'); //source sheet
var columnb = sheet.getRange('B:B'); //Column with check boxes
var columnbvalue = columnb.getValues();
var notifysheet = ss.getSheetByName('Responses'); //destination sheet
var data = [];
var rownum =[];

//Condition check in B:B (or check box column); If true copy the same row to data array

for (i=0; i<columnbvalue.length;i++) {

if (columnbvalue[i] == 'true') {

var columnb2 = sheet.getRange('B2:B');
columnb2.setValue('false');

// What you want to say in the pop up alert

var response = ui.alert('Hold Up!\n Are you sure you want to send an email to finance for this asset change?', ui.ButtonSet.YES_NO);
if (response == ui.Button.YES) {

data.push.apply(data,sheet.getRange(i+1,1,1,20).getValues());

//Copy matched ROW numbers to rownum

rownum.push(i);

//Copy data array to destination sheet


notifysheet.getRange(notifysheet.getLastRow()+1,1,data.length,data[0].length).setValues(data);

var activeRow = notifysheet.getLastRow();
var assetname = notifysheet.getRange(activeRow, 1).getDisplayValue(); // The number is the column number in the destination "responses" sheet that you want to include in the email
var owner = notifysheet.getRange(activeRow, 3).getDisplayValue();
var serial = notifysheet.getRange(activeRow, 9).getDisplayValue();
var podate = notifysheet.getRange(activeRow, 6).getDisplayValue();

var email = 'theiremail@gmail.com' //The email address in which you want to send the email notification to
var subject = 'Asset has changed department ownership!'

//Body of the email message, using HTML and the variables from above

var message =
'<br><br><div style="margin-left:40px;">Heads Up!</div>'
+'<br><br><div style="margin-left:40px;">An asset has changed department ownership.</div>'
+'<br><br><div style="margin-left:40px;"><h3 style="text-decoration: underline;">Asset Name:'+ assetname +'</h3></div>'
+'<div style="margin-left:40px;">New Departmet Owner: '+ owner +'</div><br>'
+'<div style="margin-left:40px;">Serial: '+ serial +'</div>'
+'<div style="margin-left:40px;">Purchase Date: '+ podate +'</div>'
+ '<br><br><div style="margin-left:40px;">ヽ(⌐■_■)ノ♪♬</div>';

MailApp.sendEmail(
email,
subject,
"",
{
htmlBody: message,
name: 'Sadie Stevens', //The name you want to email coming from. This will be in bold, while your e-mail address will be small in italics
});

}
}
}
}

这篇关于Google表格的脚本(自动电子邮件功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆