Domanda

I'm new to Javascript programming so this is a massive task for me - however I feel that I can do it with some help and guidance - I usually program in vb, vba, c#.

So anyway's my work colleague has asked me if I can make something that will basically tell them who is on holiday/has half a day today - currently I've got it to send an email - however when it comes to reading cells and rows.. I'm beyond clueless and this is where I am getting stuck.

This is my spreadsheet

https://docs.google.com/spreadsheet/ccc?key=0Ao7GdcoXMWiHdDNxY1k2X1hyYkhkQ210QldBeHZqaFE&usp=sharing

The summary is just the overall view of all the sheets - it shows how many holidays/half days/sick days someone has in a quick month by month view. This is updated by using the key H - holiday, BH - Bank holday, HD - half day, S - sick day, HS - half sick day and A absence in the month tabs.

So now onto what I want to achieve. Say today is 20/12/12 and Bill Bob is on holiday today - I want an email to get sent saying this - currently I have an email body set up to send and this works (kind of, the message body is just missing who is on holiday and who is on half a day) - How would I go about getting this information - I know I need to get todays date, then check that month and check the columns for H or HD before checking the row to find out who it is then storing this in a variable somewhere before compiling a list to add to the message.

How would I go about doing this though?

// Variables for the Date
var today = new Date();
var dd = today.getDate(); // Get todays date
var mm = today.getMonth()+1; // Get todays month - January is 0!

// Variables for the email
var sendEmail = false;
var emailAddress = "";
var subject = "Daily Holiday Summary";
var messagePT1 = "Good Morning,\n\nThe following people have half a day today\n\n";
var messagePT2;
var messagePT3 = "\n\nThe following people are on holiday today\n\n";
var messagePT4;
var messagePT5 = "\n\nMany thanks,\nThe Holiday Spreadsheet";
var fullMessage;

// Variables for the sheets
var sheet = SpreadsheetApp.getActiveSpreadsheet();
sheet.setActiveSheet(sheet.getSheets()[0]);

function main() {
  // This is the main function and will be the one that is ran
  findMessagePT2();
  findMessagePT4();
  sendEmail();
}

function findMessagePT2() {
  // This is the function for finding the people on half a day today

}

function findMessagePT4() {
  // This is the function for finding the people on holiday today
}

function sendEmail() {
  // This is the send email function and will send the email
  if (sendEmail == true){
    fullMessage = messagePT1 + messagePT2 + messagePT3 + messagePT4 + messagePT5;
    MailApp.sendEmail(emailAddress, subject, fullMessage);
  }
}

This is the code that I currently have, If I cant find anyone that is on holiday or on half a day I don't want the message to send - where as if someone is I do want the message to send hence the if statement in the sendEmail function.

È stato utile?

Soluzione

I posted this question on google as well to try and find some extra help,

https://productforums.google.com/forum/#!msg/docs/FQy-17QD-cc/eO5oZzbuACsJ

The correct way to do this was.

var s = sheet.getSheets()[mm];
var col=dd+1;
var lastrw=s.getDataRange().getLastRow();
var name;
var code;
for (var i=3; i<=lastrw; i++){
   name=s.getRange(i,1).getValue();
   code=s.getRange(i,col).getValue();
   if (code=="H") {messagePT2+=" name";}
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top