添加 Google 表单条目的批准步骤 ->Google Sheet/Doc
Adding approval step for Google Form entries ->Google Sheet/Doc
我希望将这个开放的 letter/Google 套件工作流程 (https://jeffreyeverhart.com/2020/05/18/open-letter-maker-with-google-forms-docs-and-apps-script/) 与需要某种形式批准的额外批准步骤结合起来(例如 Google Sheet,或者 Google Sheet 中的某种 edit/change)然后才会将信息转发给最终的 Google 文档。我已经能够使用 Jeffrey Everhart 的代码(见下文)成功设置 Google 表单 -> Google Sheet -> Google Doc 公开信工作流程获取 Google 表单信息并将其添加到表单提交时的 Google 文档中。但是我无法使脚本在 edit/on 更改触发器上工作,尽管我昨天一整天都在拔头发。那将是理想的,因为我可以简单地在 google sheet 中添加一个复选框“批准”列,它表示表单提交是否应该继续进行下一步以添加到 Google医生。有什么建议吗?
function appendSignatureRow(e) {
//Since there could be a bunch of people submitting, we lock the script with each execution
//with a 30 second timeout so nothing gets overwritten
const lock = LockService.getScriptLock();
lock.waitLock(30000);
//Here we read the variables from the form submission event
const date = new Date(e.values[0]).toLocaleDateString();
//of you can use toLocaleString method if you want the time in the doc
const name = e.values[1];
const affiliation = e.values[2];
const country = e.values[3];
//Next format those values as an array that corresponds to the table row layout
//in your Google Doc
const tableCells = [name, affiliation, country, date]
//Next we open the letter and get its body
const letter = DocumentApp.openById('INSERT ID HERE')
const body = letter.getBody();
//Next we get the first table in the doc and append an empty table row
const table = body.getTables()[0]
const tableRow = table.appendTableRow()
//Here we loop through our table cells from above and add
// a table cell to the table row for each piece of data
tableCells.forEach(function(cell, index) {
let appendedCell = tableRow.appendTableCell(cell)
})
//here we save and close our letter and then release a lock
letter.saveAndClose();
lock.releaseLock();
}
Here's the Google Sheet format I'm using, 列 F 是我希望在编辑触发器上添加批准复选标记的列,然后触发脚本在“const letter = DocumentApp.openById('INSERT ID HERE')”行。
我是 Google 应用脚本的新手,非常感谢您的帮助!
如何使用 onFormSubmit
为 Google 表单中的每个条目添加复选框,并使用 onEdit
验证复选框并写入 Google 文档。
我在这里为 onFormSubmit
创建了一个函数,它将复选框附加到新条目并修改了 appendSignatureRow()
的某些部分并将其用作 onEdit
的函数如果条目被选中,触发写入 Google 文档。
示例:
形式:
电子表格数据:
可安装触发器设置:
代码:
function formSubmit(e){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; //get form response sheet
var col = e.range.getLastColumn();
var row = e.range.getLastRow();
sheet.getRange(row, col+1).insertCheckboxes(); // add checkbox
}
function appendSignatureRow(e) {
var sheetName = e.source.getSheetName(); //get sheet name
var editedRow = e.range.getRow(); // get edited row number
var editedCol = e.range.getColumn(); //get editer column number
if(editedRow > 1 && editedCol == 6 && sheetName == 'Form Responses 1' && e.value == 'TRUE'){
const lock = LockService.getScriptLock();
lock.waitLock(30000);
var sheet = e.source.getSheetByName('Form Responses 1');
var data = sheet.getRange(editedRow, 1, 1, editedCol -1).getValues()[0]; // get edited row data
const date = new Date(data[0]).toLocaleDateString();
const name = data[1];
const affiliation = data[2];
const country = data[3];
const tableCells = [name, affiliation, country, date]
const letter = DocumentApp.openById('Insert Docs ID here')
const body = letter.getBody();
const table = body.getTables()[0]
const tableRow = table.appendTableRow()
tableCells.forEach(function(cell, index) {
tableRow.appendTableCell(cell)
})
letter.saveAndClose();
lock.releaseLock();
}
}
输出:
参考:
我希望将这个开放的 letter/Google 套件工作流程 (https://jeffreyeverhart.com/2020/05/18/open-letter-maker-with-google-forms-docs-and-apps-script/) 与需要某种形式批准的额外批准步骤结合起来(例如 Google Sheet,或者 Google Sheet 中的某种 edit/change)然后才会将信息转发给最终的 Google 文档。我已经能够使用 Jeffrey Everhart 的代码(见下文)成功设置 Google 表单 -> Google Sheet -> Google Doc 公开信工作流程获取 Google 表单信息并将其添加到表单提交时的 Google 文档中。但是我无法使脚本在 edit/on 更改触发器上工作,尽管我昨天一整天都在拔头发。那将是理想的,因为我可以简单地在 google sheet 中添加一个复选框“批准”列,它表示表单提交是否应该继续进行下一步以添加到 Google医生。有什么建议吗?
function appendSignatureRow(e) {
//Since there could be a bunch of people submitting, we lock the script with each execution
//with a 30 second timeout so nothing gets overwritten
const lock = LockService.getScriptLock();
lock.waitLock(30000);
//Here we read the variables from the form submission event
const date = new Date(e.values[0]).toLocaleDateString();
//of you can use toLocaleString method if you want the time in the doc
const name = e.values[1];
const affiliation = e.values[2];
const country = e.values[3];
//Next format those values as an array that corresponds to the table row layout
//in your Google Doc
const tableCells = [name, affiliation, country, date]
//Next we open the letter and get its body
const letter = DocumentApp.openById('INSERT ID HERE')
const body = letter.getBody();
//Next we get the first table in the doc and append an empty table row
const table = body.getTables()[0]
const tableRow = table.appendTableRow()
//Here we loop through our table cells from above and add
// a table cell to the table row for each piece of data
tableCells.forEach(function(cell, index) {
let appendedCell = tableRow.appendTableCell(cell)
})
//here we save and close our letter and then release a lock
letter.saveAndClose();
lock.releaseLock();
}
Here's the Google Sheet format I'm using, 列 F 是我希望在编辑触发器上添加批准复选标记的列,然后触发脚本在“const letter = DocumentApp.openById('INSERT ID HERE')”行。
我是 Google 应用脚本的新手,非常感谢您的帮助!
如何使用 onFormSubmit
为 Google 表单中的每个条目添加复选框,并使用 onEdit
验证复选框并写入 Google 文档。
我在这里为 onFormSubmit
创建了一个函数,它将复选框附加到新条目并修改了 appendSignatureRow()
的某些部分并将其用作 onEdit
的函数如果条目被选中,触发写入 Google 文档。
示例:
形式:
电子表格数据:
可安装触发器设置:
代码:
function formSubmit(e){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; //get form response sheet
var col = e.range.getLastColumn();
var row = e.range.getLastRow();
sheet.getRange(row, col+1).insertCheckboxes(); // add checkbox
}
function appendSignatureRow(e) {
var sheetName = e.source.getSheetName(); //get sheet name
var editedRow = e.range.getRow(); // get edited row number
var editedCol = e.range.getColumn(); //get editer column number
if(editedRow > 1 && editedCol == 6 && sheetName == 'Form Responses 1' && e.value == 'TRUE'){
const lock = LockService.getScriptLock();
lock.waitLock(30000);
var sheet = e.source.getSheetByName('Form Responses 1');
var data = sheet.getRange(editedRow, 1, 1, editedCol -1).getValues()[0]; // get edited row data
const date = new Date(data[0]).toLocaleDateString();
const name = data[1];
const affiliation = data[2];
const country = data[3];
const tableCells = [name, affiliation, country, date]
const letter = DocumentApp.openById('Insert Docs ID here')
const body = letter.getBody();
const table = body.getTables()[0]
const tableRow = table.appendTableRow()
tableCells.forEach(function(cell, index) {
tableRow.appendTableCell(cell)
})
letter.saveAndClose();
lock.releaseLock();
}
}
输出: