2014-10-10 205 views
1

我試圖寫一個小谷歌企業應用套件腳本,將發送一封確認郵件,並自動共享的文件夾與登錄的用戶,他們填寫一份表格後。下面是該腳本:谷歌Apps腳本 - 自動通過電子郵件和共享

function formSubmitReply(e) { 
    MailApp.sendEmail({ 
    to: Session.getActiveUser().getEmail(), 
    subject: "Keuka College Brand Download Center", 
    htmlBody: 
       "<p>Thank you for requesting access to the Keuka College Brand Download Center. Your access has been approved.</p>" + 
       "<p>You may access the download center by <a href='https://drive.google.com/a/keuka.edu/folderview?id=0B856ZeGoaGT_MG5BMEtEVGwzYkk&usp=sharing'>using this link,</a> " + 
       "visiting <a href='http://brand.keuka.edu'>Keuka College Brand Central,</a> or through your Google Drive.</p><p>Please contact the Office of Marketing and Communications " + 
       "with any questions you may have.</p>", 
    name: "Keuka College", 
    replyTo: "[email protected]" 
    }); 

var folder = DocsList.getFolder('Brand Download Center'); 
folder.addViewer(Session.getActiveUser()); 

}​ 

這似乎是工作,但它保持它通過電子郵件發送給我 - 不是誰填寫該表格的用戶。我不確定它是否正確共享。

有人可以提供一些見解嗎?這是我第一次使用Google Apps腳本。

回答

0

Session.getActiveUser()是使用表格編輯器,並創建調用此函數觸發用戶的用戶。

你要我們怎麼辦那漫天的形式向用戶。

查看文檔here看你如何檢索該值。請注意,它將爲only be available if you are in a domain


編輯抱歉耽擱

這裏是一個示例代碼來說明如何獲得formApp形式受訪者(僅適用於GAFE或GA業務)

它將向您發送一封郵件,其中包含最後一個表單提交者的姓名(不要忘記創建一個可安裝的onEdit觸發器來測試此信息)。

function onSubmit(){ 
    var form = FormApp.getActiveForm(); 
    var formResponses = form.getResponses(); 
    var lastResponse = formResponses[formResponses.length-1]; 
    var user = lastResponse.getRespondentEmail() 
    var userString = 'user = '+user; 
    MailApp.sendEmail(Session.getActiveUser().getEmail(),'form submission report',userString); 
} 
+0

謝謝。我改變了它如下,但它似乎仍然沒有工作。有什麼建議麼? (Partial Code):function formSubmitReply(e){ var email = e.getRespondentEmail(); MailApp.sendEmail({ 到:電子郵件, – Pete 2014-10-10 17:43:02

+0

而且您使用的企業或EDU帳戶 – 2014-10-10 17:44:40

+0

EDU,我相信 – Pete 2014-10-10 17:47:02