r/GoogleAppsScript • • Aug 08 '19

Learning google Script for spreadsheet automation

Hi, i'm new to google appscript and i don't know anything about vba either. I'm kind of confused of where to start, or if i should just read some codes or take a course.

I want to learn how to use google script to automate a spreadsheet, for example send a periodical mail to someone with to inform all the keycodes(ID) of cases that has past a due date by 2 days.

But this is just the first task i want to do, so if you have any advise on how to do it or how to approach learning google script please let me know!

Also, information and opinions of any free course is well received!

17 Upvotes

7 comments sorted by

View all comments

3

u/mytexastoast Aug 09 '19 edited Aug 09 '19

I’ve built quite a few MVPs with google sheets and app script.

Particularly a request system when a form is submitted, Someone is emailed to review the submission, every 48 hours a reminder email is sent until the submission is approved or denied on the sheet. If approved, it’s placed on a “approved this week” sheet and the contents of that are emailed out to a vendor each Friday. If denied, the user denying the request has to put a reason. That reason is then emailed back to the requester with a pre-populated google form to correct the issue and resubmit.

It sounds like what you’re trying to do is somewhat similar.

You would just need to use the query function to pull in all rows where there is no review and the submission date is < =TODAY()-Xdays

Then you would go to the script editor and paste in something like this.

function pendingReviewReminder() {

var ss = SpreadsheetApp.getActive();

var sh = ss.getActiveSheet();

var startRow = 2;

var rg = ss.getDataRange();

var vA = rg.getValues();

var message = "<p>*Automated Email* " + "</p>" + "<br> Please take a moment to review the following requests. Approved Requests are sent to our vendor early Friday mornings";

for (var i = 1; i < vA.length; i++) {

    message += "<p><b>Requester: </b>" + vA[i][4] + " " + vA[i][5] + "</p>" + "<p><b>Title: </b>" + vA[i][6] + "</p>" + "<p><b>Location: </b>" + vA[i][3] + "</p>" + "<br>";

    var SendTo = vA[i][11];

    var Subject = "Your email subject line here";

    if (SendTo != '') {

        MailApp.sendEmail({
            to: SendTo,
            cc: "",
            subject: Subject,
            htmlBody: message,
        });

        //sh.getRange(i+1,12).setValue('Yes');

    }

    message = "<p>*Automated Email* " + "</p>" + "<br> Please take a moment to review the following requests. Approved Requests are sent to our vendor early Friday mornings";

}

}

Create your trigger to fire this function once a day or every couple hours. Whatever your frequency needs are.

1

u/naxoasdf Aug 12 '19

thank you so much, it's almost exactly what i needed to do also, srry for the late response, i was completing the free course another redditor recommended, to at least be able to understand the code you wrote there.