需要Google应用脚本和脚本数据库替换示例 [英] Google apps script and script db replacement example needed
问题描述
我试图替换当前使用Script DB的处理程序。脚本数据库已被弃用。我写的信息量非常少,我想我只会将信息写入Google表单。
这里是.html的处理程序
function addApprover(){
google.script.run.withSuccessHandler(function(){
getApprovers(); $ b $($#'批准者')。val('');
})。addApprover($(#approver)。val());
}
.gs
函数addApprover(email){
var db = ScriptDb.getMyDb();
var docId = DocumentApp.getActiveDocument()。getId();
var ob = {
docId:docId,
approverEmail:电子邮件,
status:null,
emailSent:false
}
db。保存(OB);
var history = {
docId:docId,
action:'Added Approver',
email:email,
date:Utilities.formatDate(new日期(),GMT,MM-dd-yyyyHH:mm:ss),
}
db.save(history);
}
我想我仍然调用.gs函数,只需要更改功能相应。
我相当肯定文本框审批者拥有电子邮件地址。
如何访问这些项目?
我很确定我正在寻找一个for each语句来遍历每个电子邮件地址,并向他们发送消息并将其名称写入特定区域的表单,但我不确定如何继续。
我希望这会让你开始:
函数addApprover(email){
var docId = DocumentApp.getActiveDocument()。getId();
var ss = SpreadsheetApp.openById('Your Spreadsheet file ID here');
var sheetToWriteTo = ss.getSheetByName('Your sheet name here');
var rowData = [docId,email,null,false];
sheetToWriteTo.appendRow(rowData);
$ b $ var history = [docId,'Added Approver',email,Utilities.formatDate(new Date(),GMT,MM-dd-yyyy''HH:mm:ss)] ;
sheetToWriteTo.appendRow(rowData);
$ / code>
如果您想将两组数据写入两张不同的工作表,需要参考第二张表。数据进入数组,而不是对象。尽管您也会在Google文档中看到一个名为对象的数组。如果你看到方括号 []
,它就是一个数组。
如果你有任何问题, code> Logger.log()语句和/或调试和断点,然后发布另一个问题,如果它是主要问题,在这里发表评论。
I've got a google apps script UI I am using in a google doc.
I'm trying to replace the current handler which uses the Script DB. Script DB has since been deprecated. The amount of information I was writing was minimal and I figured I would just write the info to google sheets.
Here is the handler from the .html
function addApprover(){
google.script.run.withSuccessHandler(function() {
getApprovers();
$('#approver').val('');
}).addApprover($("#approver").val());
}
.gs
function addApprover(email){
var db = ScriptDb.getMyDb();
var docId = DocumentApp.getActiveDocument().getId();
var ob = {
docId: docId,
approverEmail: email,
status: null,
emailSent: false
}
db.save(ob);
var history = {
docId: docId,
action: 'Added Approver',
email: email,
date: Utilities.formatDate(new Date(), "GMT", "MM-dd-yyyy' 'HH:mm:ss"),
}
db.save(history);
}
I figure that I still call the .gs function and just need to change the function accordingly.
I'm fairly certain that the text box approver holds the email addresses.
How do I access these items?
I'm fairly certain I'm looking for a "for each" statement to iterate through each email address and send them a message and write their name to a specific area of a sheet but I am unsure how to proceed.
Hopefully this will get you started:
function addApprover(email){
var docId = DocumentApp.getActiveDocument().getId();
var ss = SpreadsheetApp.openById('Your Spreadsheet file ID here');
var sheetToWriteTo = ss.getSheetByName('Your sheet name here');
var rowData = [docId, email, null, false];
sheetToWriteTo.appendRow(rowData);
var history = [docId, 'Added Approver', email, Utilities.formatDate(new Date(), "GMT", "MM-dd-yyyy' 'HH:mm:ss")];
sheetToWriteTo.appendRow(rowData);
}
If you want to write the two sets of data to two different sheets, you'll need to get a reference to a second sheet. The data goes into an array, not an object. Although you will see an array called an object in Google documentation also. If you see brackets []
, it's an array.
If you have any problems, debug the code with Logger.log()
statements and/or debug and a breakpoint, then post another question if it's a major issue, or if it's something minor, make a comment here.
这篇关于需要Google应用脚本和脚本数据库替换示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!