2017-05-08 21 views
1

我試圖根據我的團隊在工作中使用的項目跟蹤表設置電子郵件警報系統。我需要它在任務狀態更改爲K列中的「完成」時發送電子郵件。我得到的代碼可以在測試表上工作,但是當我將其複製到活動表時,getValue()代碼停止工作?由於電子郵件是基於if()語句發送的,因此腳本運行,但實際上並不工作。我不確定這是否是權限問題,因爲我不是活動工作表的所有者? 我希望這是足夠描述性的 - 我已經教了自己的JavaScript爲了得到這個工作,它似乎如此接近,但我卡住了! 這是項目跟蹤表的外觀screenshotgetValue不適用於工作表

function emailUpdate(e) { 
 
    
 
var emailInfoRange = sheet.getRange("B:O"); 
 
    
 
var edit = e.range.getA1Notation(); // Gets edited cell location 
 
    
 
var editColumn = edit.substring(0,1) // Gets column of edited cell 
 
    
 
var editRow = edit.substring(1,3) // Gets row of edited cell 
 
    
 
if(editColumn == "K") { // gets all relevent information needed for email 
 
    
 
    var taskTypeCell = emailInfoRange.getCell(editRow,1); 
 
    var taskType = taskTypeCell.getValue(); 
 
    
 
    var requestedByCell = emailInfoRange.getCell(editRow,3); 
 
    var requestedBy = requestedByCell.getValue(); 
 
    
 
    var emailRequestCell = emailInfoRange.getCell(editRow,4); 
 
    var emailRequest = emailRequestCell.getValue(); 
 
    
 
    var projectIdCell = emailInfoRange.getCell(editRow,5); 
 
    var projectID = projectIdCell.getValue(); 
 
    
 
    var taskDescriptionCell = emailInfoRange.getCell(editRow,6); 
 
    var taskDescription = taskDescriptionCell.getValue(); 
 
    
 
    var claimedByCell = emailInfoRange.getCell(editRow,9); 
 
    var claimedBy = claimedByCell.getValue(); 
 
    
 
    var taskStatusCell = emailInfoRange.getCell(editRow,10); 
 
    var taskStatus = taskStatusCell.getValue(); 
 

 

 
    if(taskStatus == "Done") { 
 
     if(emailRequest == "Yes" || emailRequest == "yes") { // Determines if status is "Done", and email notification is "Yes" or "yes" 
 
     var emailAddress; 
 
     var getEmailAddress = function(personelArray) { // Defines function to search email address arrays for the one that belongs to requestedBy 
 
     for (var i = 0; i < personelArray.length; i++) { 
 
     if(requestedBy === personelArray[i]) { 
 
      emailAddress = personelArray[i+1]; 
 

 
     } } } 
 

 
// Searches through all email arrays to find the one belonging to requester   
 
     getEmailAddress(specialistsAndEmails) 
 
     getEmailAddress(coordinatorsAndEmails) 
 
     getEmailAddress(managersAndEmails) 
 

 
// Sends email  
 
     MailApp.sendEmail(emailAddress, 
 
         "AUTOGEN: " + taskType + " for " + projectID + " " + taskDescription + " completed by " + claimedBy + ".", "This email has been automatically generated by an edit to the work available sheet. \n" 
 
          + "PLEASE DO NOT REPLY");    
 

 
      
 
     } else (Logger.log("No email requested")) 
 
     } else (Logger.log("Status not changed to done")) 
 
     } else (Logger.log("Update not to status cell")) 
 
}

+0

當您編輯工作表時,您在腳本編輯器中的執行腳本(視圖>執行腳本)中看到了什麼?至於權限,如果你有編輯權限,你應該可以運行這個腳本。最後,每天可以發送的電子郵件的數量是一個配額,要知道你是否超過了配額? –

+0

執行記錄表明它正在經歷整個腳本。 而我不知道任何電子郵件配額,但我沒有得到它發送出去,所以它不應該被超過。 – Erin

回答

0

我會做如下修改,以幫助防止與字符串操作的問題。這可能是你getValues()的問題的原因。

function emailUpdate(e) { 
var emailInfoRange = sheet.getRange("B:O"); 
var edit = e.range // Gets edited cell location 
var editColumn = edit.getColumn() // Gets column of edited cell 
var editRow = edit.getRow() // Gets row of edited cell 

if(editColumn == 11) // Column K should correspond to column number 11, if i can count correctly. 
{ 
/// Remainder of the code should be the same as above 

} 
} 

因此,而不是範圍轉換爲A1符號的,你應該得到列數和範圍物體上使用getColumn and getRow()行數。這將防止文本到數字操作的問題,並可能是您的問題的原因。

+0

我對我的測試表和我一直有問題的活着做了這個改變。試卷仍然有效,現場試卷仍然沒有。日誌中沒有更改 – Erin

+0

您可以發佈每個日誌嗎? –

相關問題