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

  • Home
  • SEARCH
  • 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 8017765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:56:10+00:00 2026-06-04T20:56:10+00:00

I’m a bit new to the Google scripting scene. I’ve gone over this so

  • 0

I’m a bit new to the Google scripting scene. I’ve gone over this so many times and I can’t wrap my brain around incrementing properly.

I’ve created a Google Spreadsheet that uses a form. When someone uses the form to submit equipment, it’s going to use a Send Email function (MailApp.sendEmail) to e-mail it to the accounting people.

So far, I can populate the spreadhsheet perfectly, but when the function runs, it only labels the ‘status’ variable in the 1st row and doesn’t continue through the list, then it e-mails that 1 row several times. Can anyone see where I’m going so wrong on this?

I need this to submit the data to the next row that available, then the script checks the last cell for EMAIL_SENT and if it doesn’t have that value, I need it to send an e-mail and then check the next row of data as well (in case I need to manually run the script from within the spreadsheet). I couldn’t find a similar question on here where I could understand what I’m doing wrong with the incrementing and looping.

Here’s the script:

function sendThisOut() {
  // set the current spreadsheet and active sheet
  var sheet = SpreadsheetApp.getActiveSheet();

  // set range data
  var sRow = 2;  // first top left cell of data
  var cols = 9; // Num of cols 

  // define initial data source and get values
  var dataRange = sheet.getRange(sRow,1,1,cols);
  var data = dataRange.getValues();

  // increment data
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];

    // define each column
    var tstamp = row[0]; // get timestamp (col A)
    var acct = row[1]; // define account (col B)
    var cname = row[2]; // define client name (col C)
    var comment = row[3]; // define comments (col D)
    var item1 = row[4]; // defines item 1 (col E)
    var item2 = row[5]; // defines item 2 (col F)
    var item3 = row[6]; // defines item 3 (col G)
    var item4 = row[7]; // defines item 4 (col H)
    var status = row[8]; // get status (emailed or no?)

    // setup e-mail vars
    var emailAddr = "myEmail@myDomain.com";
    var subject = "ACCT:" + acct + " " + cname + " - Equipment Request";

    // setup content of e-mail
    var body = "Hello Accounting,\n\n" +
        "Please bill for the contained items on the following account:\n\n" +
        "Account: " + acct + "\n\n" +
        "Client Name: " + cname + "\n\n" +
        "Item 1: " + item1 + "\n\n" +
        "Item 2: " + item2 + "\n\n" +
        "Item 3: " + item3 + "\n\n" +
        "Item 4: " + item4 + "\n\n" +
        "Reason for rekey: " + comment;

    // check status and if it doesn't have EMAIL_SENT, email it
    if (status != "EMAIL_SENT") {
      MailApp.sendEmail(emailAddr, subject, body);
      // Make sure the cell is updated right away in case the script is interrupted
      sheet.getRange(sRow + i, 9).setValue(EMAIL_SENT);
      SpreadsheetApp.flush();
    };

  };
}

Thanks for your time!

  • 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-04T20:56:11+00:00Added an answer on June 4, 2026 at 8:56 pm

    So as mentioned above, I had to keep going over and over this. Finally, through learning a different technique and finding a few spread out threads, I ended up with the following script that:
    – simply checks the last row of data at time of submission
    – Has the user submit a form
    – Emails intended parties
    – Updates spreadsheet
    – Watches for breaks
    – Provides confirmation of email / breaks

    I hope this helps someone else out there. So far I’m still working on a script that will scan out the entire spreadsheet, but this script checks the last row on submission of a form, which answers my particular question. I’ll try to post the answer when I find my answer to the full sheet scan:

    (PS: Might be smoother to past this into Google Scripter. I’ve added a lot of comments to keep myself and anyone reading this on track of what’s going on)

    function other() {
      // set the current sheet
      var sheet = SpreadsheetApp.getActiveSheet();
    
      // set the last row and column
      var lrow = sheet.getLastRow();
      var lcol = sheet.getLastColumn();
    
      // set the major row range and data values
      var rowRng = sheet.getRange(lrow, 1, 1, lcol);
      var rowData = rowRng.getValues()[0];
    
      // setup redundancy checks for status and email
      // data status, email status and submitter are added to column headers AFTER form creation
      var statrng = sheet.getRange(lrow, 8); // set range of status
      var stat = statrng.getValue(); // get value of status in col h
      var emsrng = sheet.getRange(lrow, 9); // set range of emailed status
      var ems = emsrng.getValue(); // get value of emailed status in col i
    
      // get current submitters data and set ranges for it, then apply data to sheet
      var suberng = sheet.getRange(lrow, 10); // set range of submitters email
      var sube = Session.getActiveUser().getEmail(); // get submitters email
      suberng.setValue(sube); // set subs email to sheet in col j
    
      // setup the per cell data
      var tstamp = rowData[0]; // col a: set timestamp (created when forms created)
      var cname = rowData[1]; // col b: set the client name
      var acct = rowData[2]; // col c: set the account number cell
      var it1 = rowData[3]; // col d: set item 1
      var it2 = rowData[4]; // col e: set item 2
      var it3 = rowData[5]; // col f: set item 3
      var it4 = rowData[6]; // col g: set item 4
    
      // setup email vars
      var em = "myEmail@myDomain.com"; // email that data needs to go too
      var sub = "ACCT: " +acct+ " - " +cname+ "Request"; // subject in email
      var body = "Hello Accounting,\n\n"
          + "Please order the following:\n\n"
          + "Item 1: " +it1
          + "\nItem 2: " +it2
          + "\nItem 3: " +it3
          + "\nItem 4: " +it4
          + "\n\nPlease send us the invoicing once complete."
          + "\n\nSubmitted by\n"
          + sube + " : " + tstamp;
    
      // Now that all variables have been set, run checks and send the email as well
      // as a confirmation email. If script doesn't complete, a failure notice is sent if possible
    
      // as long as there's a timestamp and submitted status is empty, run if statement
      if (tstamp !== "" && stat == "") {
        statrng.setValue("Submitted"); // update status field since we've gotten this far
        var statu = statrng.getValue(); // make sure update took for status
        if (statu == "Submitted") {
          if (ems == "") { // no need to continue if email has already been sent, so check
            MailApp.sendEmail(em, sub, body); // send to accounting people
            emsrng.setValue("Emailed"); // update status that email was successfully sent
            // let submitter know it was a success
            MailApp.sendEmail(sube,"ACCT: " +acct+ " - Submission Successful","Your Submission was Successful!");
          }
        } else {
          // if form failed, let submitter know it was not a success
          MailApp.sendEmail(sube,"ACCT: " +acct+ " - Submission Successful","Your Submission was Successful!");
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.