0

我正在使用 Google Apps 脚本创建工作流程。我看过这个视频的大部分布局。

我在 Google Apps 脚本中构建了一个表单,该表单从用户那里获取输入数据。然后将数据提交到具有e.parameter值的行中。然后将该数据通过电子邮件发送给审批者。审批者有一个批准按钮,他们按下该按钮可将“状态”列更改为已批准。

问题: 我无法获取数据来批准正确的行。我正在传递一个row应该对应于正确行的参数,但它不起作用。

这是我将数据提交到电子表格的代码,一旦数据通过电子邮件获得批准。该DoPost函数运行并批准该行。有人可以请帮忙!我整天都在努力寻找解决方案。

function sendEmail_(e) {
  var sheet = SpreadsheetApp.openById("0AuCblud0Ss7BdHA1bXZjYXA0Y0IyekhUQm5vWG02MVE").getActiveSheet();

  var range = sheet.getRange(sheet.getLastRow() + 1, 1, 1, 13);
  range.setValues([
    [e.parameter.LastName, e.parameter.FirstName, e.parameter.DivisionName, e.parameter.EffectiveDate,
    e.parameter.Network, e.parameter.EmployeeNewPosition, e.parameter.DivisionFolder, e.parameter.SpecificIndividual,
    e.parameter.Email, e.parameter.username, e.parameter.who, e.parameter.Banner, "Unapproved"]
  ]);


  var row = sheet.getLastRow() + 1;
  //"https://script.google.com/a/macros/wichitafallstx.gov/s/AKfycbwOgTTGqNsVwnqs-xfqa7TEJWGc_lJZdoyoEoixngKdDemVQuo/exec
  var body = '<form action= <form action = " https://sites.google.com/a/macros/wichitafallstx.gov/s/AKfycbxAOGO6q9ofauf34xlDA9sLG8sUXeZsuvQkDKATOQ/exec" method ="post">' +

    "<b>Last Name:</b>" + e.parameter.LastName + '<br><br>' +
    "<b>First Name:</b>" + e.parameter.FirstName + '<br><br>' +
    "<b>Division Name:</b>" + e.parameter.DivisionName + '<br><br>' +
    "<b>Effective Date:</b>" + e.parameter.EffectiveDate + '<br><br>' +
    "<b>Network:</b>" + e.parameter.Network + '<br><br>' +
    "<b>Employee New Position:</b>" + e.parameter.EmployeeNewPosition + '<br><br>' +
    "<b>Division Folder:</b>" + e.parameter.DivisionFolder + '<br><br>' +
    "<b>Specific Individual:</b>" + e.parameter.SpecificIndividual + '<br><br>' +
    "<b>Email:</b>" + e.parameter.Email + '<br><br>' +
    "<b>Username:</b>" + e.parameter.username + '<br><br>' +
    "<b>who:</b>" + e.parameter.who + '<br><br>' +
    "<b>Banner:</b>" + e.parameter.Banner +

    '<br />' +
    '<br />' +
    '<input type="hidden" name="row" value=" ' + row + ' "/>' +
    '<input type="submit" value="Approve" onclick="approve()" />' +
    '</form>';

  var owners = SitesApp.getSite("wichitafallstx.gov", "information-systems").getOwners();
  var mail = MailApp.sendEmail(owners.join(","), "test", '', {
    htmlBody: body
  });
}

//handles the payload that is posted back to appscript..from the form that is passed from the form created in send email.
function doPost(e) {
  var r = e.parameter["row"];
  var sheet = SpreadsheetApp.openById("0AuCblud0Ss7BdHA1bXZjYXA0Y0IyekhUQm5vWG02MVE").getActiveSheet();
  var values = sheet.getRange(r, 1, 1, 13).getValues();

  sheet.getRange(r, 13).setValue("Approved");

}
4

1 回答 1

1

我正在传递一个应该对应于正确行但它不起作用的行参数。

看来您正在传递预期行下方的行。

  var range = sheet.getRange(sheet.getLastRow() + 1, 1, 1, 13);
  range.setValues([
    [e.parameter.LastName, e.parameter.FirstName, e.parameter.DivisionName, e.parameter.EffectiveDate,
    e.parameter.Network, e.parameter.EmployeeNewPosition, e.parameter.DivisionFolder, e.parameter.SpecificIndividual,
    e.parameter.Email, e.parameter.username, e.parameter.who, e.parameter.Banner, "Unapproved"]
  ]);

// In assignment below 'new' lastRow is the row you just filled 
// in with above and should not include + 1
  var row = sheet.getLastRow()   // no + 1;
于 2013-01-31T02:21:22.297 回答