0

理念:建立一个表的emailer

  • 用户从打开谷歌工具栏菜单中选择“电子邮件”。
  • 它提示用户用单选按钮来选择自己的领域办公地点,并用文本区域
  • 用户点击提交和“FFO_Email”功能添加了额外的消息在电子邮件正文运行

“FFO_Email”功能将根据无线电选择

  • 做以下

    • 决定现场办公地点确定电子邮件的基于现场办公地点(“FFO-IS” A3列表! A12)和电子邮件在右边的“FFO-IS”片(“FFO-IS” B3:H12)
    • 创建电子邮件主题
    • 创建电子邮件正文(将在侧边栏
    • 包括从文本区域的其他消息
    • 最后发送电子邮件的个人和显示邮件已在侧边栏成功发送我有

      的选择

    问题的消息无线电广播Field Office位置和其他消息不传递到FFO_Email.gs函数。因此不会将电子邮件发送给个人。

    表可以在这里

    发现https://docs.google.com/a/cougars.ccis.edu/spreadsheets/d/1PK18AXMlfC2reKRP7IJWHRT9TEnDzfWa3g-uavgsxUk/edit?usp=sharing

    FFO_email.html

    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> 
     
    <!DOCTYPE html> 
     
    <html> 
     
    
     
    <head> 
     
        <base target="_top"> 
     
    
     
        <script> 
     
        function onSuccess(fieldOffice, AdditionalMessage) { 
     
         var div = document.getElementById('fieldOfficeFFO'); 
     
         div.innerHTML = 'Email for ' + fieldOffice + ' has been sent successfully.'; 
     
        } 
     
        google.script.run.withSuccessHandler(onSuccess) 
     
         .FFO_Email(); 
     
        </script> 
     
    
     
    </head> 
     
    
     
    <body> 
     
    
     
        <form id=fieldOfficeFFO> 
     
    
     
        <fieldset style="background-color:LightGray;width:250px"> 
     
    
     
         <div> 
     
         <label for="Field Office Select">Please select your field office below.</label> 
     
         </div> 
     
    
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="ARK_E_TEXAS"> 
     
         <label for="ARK_E_TEXAS">ARK_E_TEXAS</label> 
     
         </div> 
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="BORDER_EAST"> 
     
         <label for="BORDER_EAST">BORDER_EAST</label> 
     
         </div> 
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="BORDER_WEST"> 
     
         <label for="BORDER_WEST">BORDER_WEST</label> 
     
         </div> 
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="CENTRAL_TEXAS"> 
     
         <label for="CENTRAL_TEXAS">CENTRAL_TEXAS</label> 
     
         </div> 
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="DALLAS"> 
     
         <label for="DALLAS">DALLAS</label> 
     
         </div> 
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="FORT_WORTH"> 
     
         <label for="FORT_WORTH">FORT_WORTH</label> 
     
         </div> 
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="GULF_COAST"> 
     
         <label for="GULF_COAST">GULF_COAST</label> 
     
         </div> 
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="LOUISIANA"> 
     
         <label for="LOUISIANA">LOUISIANA</label> 
     
         </div> 
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="NEW_MEXICO"> 
     
         <label for="NEW_MEXICO">NEW_MEXICO</label> 
     
         </div> 
     
         <div> 
     
         <input type="radio" name="fieldOfficeFFO" id="fieldOfficeFFO" value="OKLAHOMA"> 
     
         <label for="OKLAHOMA">OKLAHOMA</label> 
     
         </div> 
     
        </fieldset> 
     
    
     
        <br> 
     
        <br> 
     
    
     
        <fieldset> 
     
         <div class="form-group"> 
     
         <label for="AdditionalMessage">Additional Message</label> 
     
         <textarea id="AdditionalMessage" rows="3" style="width:250px"></textarea> 
     
         </div> 
     
        </fieldset> 
     
    
     
        </form> 
     
    
     
        <div class="block"> 
     
        <button class="blue" onclick="onSuccess(fieldOfficeFFO,AdditionalMessage)">Submit</button> 
     
        <button onclick="google.script.host.close()">Close</button> 
     
        </div> 
     
    
     
    </body> 
     
    
     
    </html>

    FFO_Email.gs

    function FFO_Email(fieldOfficeFFO, AdditionalMessage) { 
     
        var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('FFO-IS') 
     
        var firstRow = 3; 
     
        var lastRow = 10; 
     
        var dataRange = sheet.getRange(firstRow, 1, lastRow, 8); 
     
        var myDate = new Date(); 
     
        var hrs = myDate.getHours(); 
     
    
     
        //Determines the row the Field Office is in 
     
        for (var j = 0; j < dataRange.length; j++) { 
     
        if (dataRange[j][0] == fieldOfficeFFO) { 
     
         Logger.log((j + 1)) 
     
         return j + 1; 
     
        } 
     
        } 
     
    
     
        //Create the greeting based on the time of day 
     
        var greeting; 
     
    
     
        if (hrs < 12) 
     
        greeting = 'Good Morning'; 
     
        else if (hrs >= 12 && hrs <= 17) 
     
        greeting = 'Good Afternoon'; 
     
        else if (hrs >= 17 && hrs <= 24) 
     
        greeting = 'Good Evening'; 
     
    
     
    
     
        // Fetch values for each row in the Range. 
     
        var data = dataRange.getValues(); 
     
        for (i in data) { 
     
        var row = data[i]; 
     
    
     
        var field_Office = fieldOfficeFFO; 
     
        var PT_Director = dataRange.getValues(j, 2); 
     
        var PT_Manager = dataRange.getValues(j, 3); 
     
        var PT_Management_Specialist = dataRange.getValues(j, 4); 
     
        var Area_Supervisory_AM = dataRange.getValues(j, 5); 
     
        var Area_AM = dataRange.getValues(j, 6); 
     
        var SC_Senior_Property_Manager = dataRange.getValues(j, 7); 
     
        var AMS = dataRange.getValues(j, 8); 
     
        var email_Subject = field_Office + " FFO/Income Statement Report is ready for viewing"; 
     
        var message_Body = greeting + "," + 
     
         "<br> <br>" + 
     
         "The " + field_Office + " <b>FFO/Income Statement Report is ready for viewing in</b> the <i>AMS Standard Reports - R07 Google Folder</i>" + 
     
         " located at https://drive.google.com/drive/u/0/folders/0Bx1aKS2V9K-kb0tNLXFfbGtmalE" + 
     
         "<br> <br>" + 
     
         "<br> <br>" + 
     
         //Additional Message from html side added here 
     
         AdditionalMessage + 
     
         "<br> <br>" + 
     
         "Thank you." + 
     
         "<br> <br>" + 
     
         AMS; 
     
    
     
    
     
        //Send email 
     
        MailApp.sendEmail({ 
     
         to: SC_Senior_Property_Manager + "," + Area_AM + "," + AMS, 
     
         cc: PT_Director + "," + PT_Manager + "," + PT_Management_Specialist + "," + Area_Supervisory_AM, 
     
         replyTo: AMS, 
     
         subject: email_Subject, 
     
         htmlBody: message_Body 
     
        }); 
     
        return fieldOfficeFFO 
     
        SpreadsheetApp.flush(); 
     
        Utilities.sleep(1000); 
     
        } 
     
    }

  • 回答

    0

    在同一组无线电输入可以不具有相同的id=。 给他们相同的名称属性是好的,如果这是你想如何分组他们。 Textarea根本没有name=属性。

    0

    有相当需要做出一些改动:

    我想创建,提交一个新的功能,我称之为sendInputInfo()

    脚本标签:

    <script> 
        function sendInputInfo() { 
        console.log('sendInputInfo ran!');//Open browsers console to see print out 
        //Get the form information to be sent 
        var theFormElement = document.getElementById('fieldOfficeFFO'); 
    
        google.script.run.withSuccessHandler(onSuccess) 
         .FFO_Email(theFormElement); 
        }; 
    
        function onSuccess(fieldOffice, AdditionalMessage) { 
        div.innerHTML = 'Email for ' + fieldOffice + ' has been sent successfully.'; 
        }; 
    </script> 
    

    更改onclick属性:

    <button class="blue" onclick="sendInputInfo()">Submit</button> 
    

    注ŧ在括号中没有值被发送到函数。这不是必需的。该表格正在sendInputInfo()函数中检索。

    目前,代码没有将任何信息传递给服务器。有没有在服务器功能的括号:

    目前:

    .FFO_Email(); 
    

    需要有东西在括号:

    .FFO_Email(theFormElement); 
    

    .gs代码已在括号两个参数。如果应用程序脚本是表单对象,它将只接受服务器端的一个输入。因此,您需要将功能更改为:

    function FFO_Email(theFormObject) { 
        Logger.log('theFormObject: ' + theFormObject);//Should be an object 
        Logger.log('theFormObject.fieldOfficeFFO: ' + theFormObject.fieldOfficeFFO); 
    
        for (var key in theFormObject) {//Loop through all the data in the form 
        Logger.log('key: ' + key); 
        Logger.log('value: ' + theFormObject[key]); 
        }; 
    
    +0

    我通读了您的答案并进行了更改,但仍然没有运气。我很好奇所选收音机和附加信息从HTML端传递到Google Apps脚本端 –

    +0

    您需要从头到尾调试代码。你需要弄清楚有多少代码正在工作,以及它停止工作的地方。除了不能工作的地方以外的一切都不可信。在最后看到最新的答案。您需要确定服务器接收数据的内容。布赖恩P是正确的'id's'。删除所有'id =“fieldOfficeFFO”'属性,它们是无用的。应用程序脚本将**不允许在表单对象中传递id,只有名称。 –

    +0

    我已经做出了您所建议的更改,并将更多内容读入您所做的更改中。该脚本现在将电子邮件发送到个人列表,但表单并未说明电子邮件已发送。此外,我做了更多的改变,不再符合我原先发布的代码,但仍在寻求相同的结果。我应该开始一个新问题还是应该更新我的问题? –