通过其索引选择行的特定数据

时间:2019-03-08 07:10:24

标签: google-apps-script google-sheets appscript

我正在使用gg表单和gg表为我的公司创建批准工作流。如下图所示,每当批准者在H列中选择批准或拒绝时,电子邮件将自动生成并使用下面表格中的数据,然后发送给安全人员。

我面临的问题是,例如,批准者批准了第4行的请求,我不知道如何获取第4行的数据,然后创建包含第4行数据的电子邮件。我已经使用了getRowIndex函数,但是以某种方式失败了。这是我的代码:

var sheet = SpreadsheetApp.openById('1NoVx8cLL_x4QAJA_hNIP3bwdpwMyiSn6WZ4iGBb53Tg');
var ss = sheet.getSheetByName('Approval');
var data = ss.getDataRange().getValues();
var lastRow = ss.getLastRow();
var Status = ss.getRange(lastRow, 8).getValue();
var Index = ss.getRange(lastRow, 8).getRowIndex();

function OnEdit(e) {
  var data = Onsubmitssion();
  if(Status == 'Approve'){
    SendApprovedEmail(data);
    SendEmailSecurityInform(data);
  }
    if(Status == 'Reject'){
    SendRejectedEmail(data);
  }
}
function Onsubmitssion(data){
  this.SPName = ss.getRange(Index, 3).getValue();
  this.Quantity = ss.getRange(Index, 4).getValue();
  this.VendorName = ss.getRange(Index, 5).getValue();
  var AttachmentID = ss.getRange(Index, 6).getValue();
  this.res = AttachmentID.substring(33);
  var res = AttachmentID.substring(33);
  var files = DriveApp.getFileById(res);
  DriveApp.getFolderById("1D274UGBirLMFdyafNAAN2_463m1990z2").addFile(files);
  files.addViewer('tung_hoang@colpal.com');
  return this;
}
function SendApprovedEmail(data){
  var Requestor = ss.getRange(Index, 2).getValue();
    MailApp.sendEmail({
    to:Requestor,
    subject: "Approval for spare part lending",
    htmlBody: htmlEmailApproved(data)
  });
}

function SendRejectedEmail(data){
  var Requestor = ss.getRange(Index, 2).getValue();
    MailApp.sendEmail({
    to:Requestor,
    subject: "Spare part lending rejected",
    htmlBody: htmlEmailRejected(data)
  });
}
function SendEmailSecurityInform(data){
    MailApp.sendEmail({
    to:'tung_hoang@colpal.com',
    subject: "Yêu cầu mang hàng ra cổng",
    htmlBody: htmlEmailSecurity(data)
  });
}

enter image description here

0 个答案:

没有答案