Time Off Request and Setting date to mm/dd/yyyy format

huangapple go评论57阅读模式
英文:

Time Off Request and Setting date to mm/dd/yyyy format

问题

我想要运行的是已经填写的单元格。无论是在列F和K中填写全天的情况,还是在列I中填写迟到的情况。

另外,一个不错的附加功能是在发送电子邮件后将该行移动到“已批准”选项卡。

英文:

To start with I am a total novice at GAS. Im trying to a digital time-off request using google forms and google sheets that sends out an email when approved.

I have it working but I am running into an issue because I want to print the time in a format without the extra time at the end.

I was able to get it to work by adding .toLocaleDateString("en-US") to the variables but I realized it wont work if the the cell is blank.

I would like that to run on the cell that is filled. Either column f&k when a full day is taken or column I if late.

A nice extra would be after the email is sent the row is moved to the "approved" tab.

A copy of the google sheet is here: https://docs.google.com/spreadsheets/d/1HdFERMvFtgcmqoPOe4yvD7i-HyFgo132wCnTaY-IGwA/edit?usp=sharing

function sendEmailedit(e){
if (e.range.columnStart != 12 || e.value != "TRUE") return;    
const rData = e.source.getActiveSheet().getRange(e.range.rowStart,1,1,11).getValues();
let y = rData\[0\]\[10\];
let late = rData\[0\]\[8\]
let beg = rData\[0\]\[5\];
let end = rData\[0\]\[6\];
let ESLP = "https://docs.google.c"
let Subject = "Staff absence/time off request for";
let cc = "pn, td, ma"
let msg = "Your staff absence/late request for" + " " + beg + "-" + end + " " + late + " " +           "has been approved by ." + "<p>" +
 "<b>\<u\>All Staff:</b>\</u\>" + "<br>" +
 "Please add a banner reminder (all day) onto Google Calendar and include both es and es" + "       <p>" +
"<b>\<u\>Teachers:</b>\</u\>" + "<br>" +
"Please email your lesson plans to ma and pn by 8:00am the day you will be out" + "<p>" +
"<b>\<u\>Sub plans must include:</b>\</u\>" + "<br>" +
"classroom procedures, clear directions for the scholars/ substitute, and an agenda with time         stamps. You can use your own template or the" + " " + '\<a href="' + ESLP + '"\>ESAT Sub Lesson     Plan</a>' + "<p>" +
"Thank you!";

Logger.log(msg);

GmailApp.sendEmail( y , "Staff absence/late request", msg,{
htmlBody: msg});
}

Thank you for any help!

I would like that to run on the cell that is filled. Either column f&k when a full day is taken or column I if late.

A nice extra would be after the email is sent the row is moved to the "approved" tab.

答案1

得分: 0

const rData = e.source.getActiveSheet().getRange(e.range.rowStart, 1, 1, 11).getDisplayValues();

Then you may also use this code to move that row to "Approved" sheet:

var sourceSheet = e.source.getActiveSheet();
var row = e.range.getRow();
var rowRange = sourceSheet.getRange(row, 1, 1, sourceSheet.getLastColumn());
var rowValues = rowRange.getDisplayValues()[0];
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Approved");
targetSheet.appendRow(rowValues);
sourceSheet.deleteRow(row);

Final code:

function sendEmailedit(e) {
  if (e.range.columnStart != 12 || e.value != "TRUE") return;
  const rData = e.source.getActiveSheet().getRange(e.range.rowStart, 1, 1, 11).getDisplayValues();
  let y = rData[0][10];
  let late = rData[0][8];
  let beg = rData[0][5];
  let end = rData[0][6];
  let ESLP = "https://docs.google.com/document/";
  let Subject = "Staff absence/time off request for";
  let cc = "test1@email.com, test2@email.com, test3@email.com";
  let msg = "Your staff absence/late request for" + " " + beg + "-" + end + " " + late + " " + "has been approved by Ms." + "<p>" +
    "<b><u>All Staff:</b></u>" + "<br>" +
    "Please add a banner reminder (all day) onto Google Calendar and include both test4@email.com and test5@email.com" + "<p>" +
    "<b><u>Teachers:</b></u>" + "<br>" +
    "Please email your lesson plans to test@email.com and test2@email.com by 8:00am the day you will be out" + "<p>" +
    "<b><u>Sub plans must include:</b></u>" + "<br>" +
    "classroom procedures, clear directions for the scholars/ substitute, and an agenda with time stamps. You can use your own template or the" + " " + '<a href="' + ESLP + '">ESAT Sub Lesson Plan</a>' + "<p>" +
    "Thank you!";

  Logger.log(msg);

  GmailApp.sendEmail(y, "Staff absence/late request", msg, {
    htmlBody: msg
  });

  //Move this row
  var sourceSheet = e.source.getActiveSheet();
  var row = e.range.getRow();
  var rowRange = sourceSheet.getRange(row, 1, 1, sourceSheet.getLastColumn());
  var rowValues = rowRange.getDisplayValues()[0];
  var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Approved");
  targetSheet.appendRow(rowValues);
  sourceSheet.deleteRow(row);
}

Reference:


<details>
<summary>英文:</summary>
**From:**
const rData = e.source.getActiveSheet().getRange(e.range.rowStart,1,1,11).getValues();
**To:**
const rData = e.source.getActiveSheet().getRange(e.range.rowStart,1,1,11).getDisplayValues();
Then you may also use this code to move that row to &quot;Approved&quot; sheet:
var sourceSheet = e.source.getActiveSheet();;
var row = e.range.getRow();
var rowRange = sourceSheet.getRange(row, 1, 1, sourceSheet.getLastColumn());
var rowValues = rowRange.getDisplayValues()[0];
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;Approved&quot;);
targetSheet.appendRow(rowValues);
sourceSheet.deleteRow(row);
Final code:
-----------
**Try:**
function sendEmailedit(e) {
if (e.range.columnStart != 12 || e.value != &quot;TRUE&quot;) return;
const rData = e.source.getActiveSheet().getRange(e.range.rowStart, 1, 1, 11).getDisplayValues();
let y = rData[0][10];
let late = rData[0][8]
let beg = rData[0][5];
let end = rData[0][6];
let ESLP = &quot;https://docs.google.com/document/&quot;
let Subject = &quot;Staff absence/time off request for&quot;;
let cc = &quot;test1@email.com, test2@email.com, test3@email.com&quot;
let msg = &quot;Your staff absence/late request for&quot; + &quot; &quot; + beg + &quot;-&quot; + end + &quot; &quot; + late + &quot; &quot; + &quot;has been approved by Ms.&quot; + &quot;&lt;p&gt;&quot; +
&quot;&lt;b&gt;&lt;u&gt;All Staff:&lt;/b&gt;&lt;/u&gt;&quot; + &quot;&lt;br&gt;&quot; +
&quot;Please add a banner reminder (all day) onto Google Calendar and include both test4@email.com and test5@email.com&quot; + &quot;&lt;p&gt;&quot; +
&quot;&lt;b&gt;&lt;u&gt;Teachers:&lt;/b&gt;&lt;/u&gt;&quot; + &quot;&lt;br&gt;&quot; +
&quot;Please email your lesson plans to test@email.com and test2@email.com by 8:00am the day you will be out&quot; + &quot;&lt;p&gt;&quot; +
&quot;&lt;b&gt;&lt;u&gt;Sub plans must include:&lt;/b&gt;&lt;/u&gt;&quot; + &quot;&lt;br&gt;&quot; +
&quot;classroom procedures, clear directions for the scholars/ substitute, and an agenda with time stamps. You can use your own template or the&quot; + &quot; &quot; + &#39;&lt;a href=\&quot;&#39; + ESLP + &#39;&quot;&gt;ESAT Sub Lesson Plan&lt;/a&gt;&#39; + &quot;&lt;p&gt;&quot; +
&quot;Thank you!&quot;;
Logger.log(msg);
GmailApp.sendEmail(y, &quot;Staff absence/late request&quot;, msg, {
htmlBody: msg
});
//Move this row
var sourceSheet = e.source.getActiveSheet();;
var row = e.range.getRow();
var rowRange = sourceSheet.getRange(row, 1, 1, sourceSheet.getLastColumn());
var rowValues = rowRange.getDisplayValues()[0];
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;Approved&quot;);
targetSheet.appendRow(rowValues);
sourceSheet.deleteRow(row);
}
**Reference:**
- [Copy/Move row to another sheet][1]
[1]: https://sheetautomation.com/blog/copy-move-row/
</details>

huangapple
  • 本文由 发表于 2023年2月10日 06:05:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404920.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定