Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9072895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:16:57+00:00 2026-06-16T18:16:57+00:00

I am still learning the ropes here. Based on code suggested by other contributors,

  • 0

I am still learning the ropes here. Based on code suggested by other contributors, I put together a script to send reminder emails to consultants who record their time entries using a Google Form. The spreadsheet first imports calendar entries with all the Job information for each consultant. After the calendar entries are imported, if the consultant has not yet recorded their time entry, the following script will send them an email with a reminder to do so:

function sendReminder() {

  var rmndrFrom = "XYZ, Inc.";
  var myemail   = "support@xyz.com";

  var sheet     = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Pending");
  var numRows   = sheet.getLastRow();
  var lastCol   = sheet.getLastColumn();
  var dataRange = sheet.getRange(2, 1, numRows, lastCol); // row 1 is the header row
  var sheetData = dataRange.getValues();

  for (var i = 0; i < sheetData.length; ++i) {
    var row = sheetData[i];
    if (row[0]){
      var jobNumb = row[0]; // Job Number
      var conName = row[2]; // Consultant Name
      var conMail = row[3]; // Consultant Email
      var jobDate = row[4]; // Date

      // format email string
      var subject = "Time Entry Reminder: " + conName + " / Job " + jobNumb;

        try {
          var conMsgH = 'This is a reminder for you to record your time entry for Job #<strong>' + jobNum + '/' + jobDate + '</strong>';

          // strip HTML for plain text message
          var conMsgP = conMsgH.replace(/\<br\/\>/gi, '\n').replace(/(<([^>]+)>)/ig, "");

          // send reminder to consultants
          MailApp.sendEmail(conMail, subject, conMsgP, { htmlBody:conMsgH, name:rmndrFrom });

        } catch (e) { // error handler
          MailApp.sendEmail(myemail, "Error in sending reminder email.", e.message);
        }
      }
  }
}

So basically, this script parses the Pending sheet, if column A has a Job Number, it will send a reminder email to the consultant with that Job Number. However, a single consultant may have several job numbers to their name. I would like the script to send a single email to each consultant with a list of the Job Numbers for which they have to record their time entries.

Thanks in advance for your kind help. Any suggestions on how to optimize the code will also be very much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:16:59+00:00Added an answer on June 16, 2026 at 6:16 pm

    There are a number of ways that you can approach this. One way is to keep a sheet with the consultants emails, names and a list of their job numbers. Load this data into your script, a list of all job ids and the job info. Then filter the job ids based on the consultants list and build your email, or you could just send that list of numbers for a very short script.

    Another way is to do all of that sorting per consultant in the code and send out the emails that way. This is the approach I’ve taken, and I’ve also made use of the iterative JS functions map, filter and reduce more details at MDN.

    The code is posted below, but if you would like to take a look at it attached to a spreadsheet and commented (as well as the functions to build that extra sheet with just the consultants info on it) take a look here.

    Below is my iteration of your function. I hope it is helpful for your situation:

    var rmndrFrom = "XYZ, Inc.";
    var myemail   = "me@emailisawesome.com";
    var subject   = "Time Entry Reminder";
    
    function sendReminder() {
      var sheet       = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Pending");
      var numRows     = sheet.getLastRow();
      var lastCol     = sheet.getLastColumn();
      var sheetData   = sheet.getRange(2, 1, numRows-1, lastCol).getValues();
      var cons = sheet.getRange(2,3,numRows-1,1).getValues().reduce(flatten_).filter(getUniqueConsultants_);
      cons.forEach(sendEmail_, sheetData);
    }
    
    function sendEmail_(consultant) {
      var consultantsJobs = this.filter(getJobsForConsultant_, consultant);
      var jobList = consultantsJobs.map(buildJobLine_).join("<br>"); 
      try {
        var conMsgH = "Hi " + consultant + ",<br>";
        conMsgH    += "This is a reminder for you to record your time entry for the following jobs:<br><br>";
        conMsgH    += jobList;
        conMsgH    += "<br><br>Thank you for your cooperation.";
        var conMsgP = conMsgH.replace(/\<br\/\>/gi, '\n').replace(/(<([^>]+)>)/ig, "");
        MailApp.sendEmail(consultantsJobs[0][3], subject, conMsgP, {htmlBody:conMsgH, name:rmndrFrom});
      } catch (e) {
        MailApp.sendEmail(myemail, "Error in sending reminder email.", e.message);
      } 
    }
    
    function buildJobLine_(job) {
      return "Job #" + job[0] + " on " + Utilities.formatDate(job[4], Session.getTimeZone(), "MMM dd yyyy");
    }
    
    function getJobsForConsultant_(row) {
      return row[2] == this;
    }
    
    function getUniqueConsultants_(v,i,a) {
      return a.indexOf(v) == i;
    }
    
    function flatten_(a,b) {
      return a.concat(b);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm still learning the ropes of Git (love it!) but the other day I
Ok, so I'm still learning the ropes of C++ here so I apologize if
Newbie still learning, been trying to search and hack code together for hours now,
im not the best when it comes to SQL still learning the ropes. I
Still learning Objective-C / iPhone SDK here. I think I know why this wasn't
Still learning JSP Web Applications here. I have been doing this for a while
I'm still learning the WPF ropes, so if the following question is trivial or
I'm still learning the ropes for Entity expressions, and I have this SQL query
I'm still learning the ropes of OLAP, cubes, and SSAS, but I'm hitting a
... and thanks for reading... I'm still learning the ropes so please be forgiving...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.