2017-05-08 6 views
1

직장에서 사용하는 프로젝트 추적 시트를 기반으로 이메일 알림 시스템을 설정하려고합니다. 작업 상태가 K 열의 "완료"로 변경되면 이메일을 보내야합니다. 테스트 시트에서 작업 할 코드가 있는데, 실제 시트에 복사하면 getValue() 코드가 작동을 멈 춥니 다. 전자 메일은 if() 문을 기반으로 전송되므로 스크립트는 실행되지만 실제로는 작동하지 않습니다. 내가 라이브 시트의 소유자가 아니기 때문에 권한 문제인지 확실하지 않습니다. 충분히 설명 적이기를 바란다 - 나는이 일을하기 위해 자바 스크립트를 가르쳤다. 그리고 그것은 매우 가깝게 보인다. 그러나 나는 붙이게된다! 프로젝트 추적 시트의 모양은 screenshot입니다.getValue가 시트에서 작동하지 않습니다.

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

각각에 대해 얻은 로그를 게시 할 수 있습니까? –