I am hoping i can find a kind hearted person to help me if possible with some google sheets scripting.
I am looking for a way to automate something i currently have to do manually everyday. I take data from present day I have entered into a spreadsheet, copy it, paste it into and email and send it. I have used the Query function within Google sheets to help me separate who gets what information, that has made my life a tad bit easier.
I currently go to each tab, copy data, go to Gmail, paste data, type in the email address of the recipient, type in the subject, send, then go on to the next one 30+ times.
What I would like to do...
1. Click a menu item at top that says something like "Send Emails Now"
2. Once triggered, this would go to all (except 3, but i can just have these go to my own junk mail if too much) the tabs and send an email with the information contained only on that sheet to an email address in Cell A2
Email would have the subject "Call Parking Time XXXXXX" where XXXX is the date in a E1
Here is a copy of the current sheet I have, some reason it will not let me share the original. So i have updated the 20-Sioux Falls and 21-Frederick sheets to show what i mean.
https://docs.google.com/spreadsheets/d/1nOgZzwbKEUF4_adkjxkvmiiVwFtu-2OGCPJ0Wj_keQU/edit?usp=sharing
Thank you for your help in advance.
Although this is an older question, I still have a recommendation for you and other potential users facing the same problem.
I use a Google Sheets add-on called FormMule that should work as a great solution to your challenge here. It allows you to create personalized template emails, set conditions for your merge, and have multiple templates to various people based upon your chosen criteria.
You can also set a time trigger, form submission trigger, or manually trigger it through the add-on menu.
Although I agree with Zig, here are a few things that'll help you get started:
//1. Define your Custom Menu Item
function onOpen() {
var spreadsheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'Send Data', functionName: 'sendEmail_'}
];
spreadsheet.addMenu('Automated Emails', menuItems);
}
Tutorial for Sending Email (Although this one sends data in each row as a separate email but you should get the idea of what to do)
Sample for creating a table from Spreadsheet Data
This should give you a good head-start. Put pieces of these together and you should be pretty much good to go. And if you hit any roadblocks along the way, people on SO are always glad to help. :)
Related
I'm trying to come up with a solution that will allow me to (1) pull data from Sheets for only ONE of the rows into a Gmail template and (2) allow for modifying the template with additional information that's not in the spreadsheet before sending it off.
Context: My organization uses an intake/referral log to track key information about referrals. Once info is in the Sheet, they manually send an email assigning the referral to an employee for follow-up. Much of the info in the Sheet is retyped...which initially made me think of automating this fully with AppsScript, so that all the standard info (case #, case type, due dates, etc) is included in that email. However, the emails sometimes have a paragraph or three of contextual information that we don't want to store in the spreadsheets and have pulled into the automated email.
So my goal is to pull the data from the spreadsheet into the email where I can (vs having to retype it) AND allow the addition of contextual info before sending it off to the assigned employee.
Any thoughts on how to accomplish this? I haven't found a mail merge add-on or Apps Script solution that allows doing this one row at a time and adding in extra custom info into the email.
Thanks in advance!
So this question, as currently written, could clearly be accomplished a whole bunch of different ways. With that in mind, here is one quick and dirty way in which it might be accomplished:
On the spreadsheet where the data is stored, create a script via tools>script editor.
Using that script, create a menu which runs a function that does the following, perhaps in an endless loop:
a. Prompt the user for the email address of where to send the email if it isn't in the spreadsheet or a token value, such as an empty string, to end the script.
b. Prompt the user for the number of the row where the info is stored.
c. Prompt the user for any extra contextual information to add to the email.
d. Get the info from the applicable row in the spreadsheet.
e. Create a nicely formatted email and send it off.
From there, the person in charge of doing the referrals would simply run the script and feed it the required information. Clearly human error could fowl things up here, but without more details of exactly how you want this to work, it isn't really possible to define exactly how to best protect against human error. Reading up on Data Validation might give you a start on that front.
And if you are still completely lost, I happen to be a Google Apps Script tutor/consultant who often gives away free tutoring/consulting. See tutoringbyroger.com for more on that.
I hope that helps.
I've been promoted into developing & maintaining a Google Sheets database at work. I know very little about Google Sheets scripting & from asking around, and researching it's looking like GAS is probably the avenue that I need to start heading down.
So we have 3 Workbooks in Google Sheets; 2 contain large amounts of data, the other workbook provides a UI for our sales dpt. to access the data. I really wish I could share these with you, as describing them is difficult. In the UI workbook, separate pages are paired with sheets in the one database (lets call it database A).
A salesman will go to the UI sheet for the product he's selling a device for; the top section of the sheet allows him to select, essentially, a row from database A. After the selection is made, the rest of the sheet is populated with products we manufacture that work with the choice made in the top section; the products we make are stored in the other database ("B"). We have to have two databases, as we've earlier hit the cell-limit in sheets with the two databases combined.
On average each UI page has about 150 Importranges. Looking up done with Query.
Our problem is that this UI is getting pretty slow, initial load time makes it worthless for salesmen on the road, and annoying to the salesmen here in the office. The delay when making the initial selections (querying database A) is usable, but still much slower then we'd like. And we're not finished building UI pages.
I've seen online that most people recommend using Apps Script to replace importrange, but knowing nothing about Apps Script, I haven't been able to understand what is being done, or mainly how to take the apps script and actually put the data in the cells.
So I'd appreciate any help I could get in speeding this up.
First let me say that the Google Apps script documentation has improved greatly over the years and I find it pretty easy to use now. If you open up a code editor in Google Sheets and go to Help menu and select API reference then that links you up to just about everything you need to know. If you go to the Google Apps reference for spreadsheets and look at the SpreadsheetApp object you'll see that there's three commands to open up another Spreadsheet not a sheet but a Spreadsheet. You can do it by file, by id or by URL.
If you click on the Url command it will take you to an example like this:
// The code below opens a spreadsheet using its id and logs the name for it.
// Note that the spreadsheet is NOT physically opened on the client side.
// It is opened on the server only (for modification by the script).
var ss = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/abc1234567/edit');
Logger.log(ss.getName());
As it points out, it doesn't actually open the file on the client-side it just opens it up on the server. So it may be necessary for you to open them up manually at first just to get an idea of what they look like. Once you know how they are organized then you can use the open command to get a Spreadsheet Object and from it select a specific sheet and then a data range. Once you have a range then you can load an array like this.
var myArray = rng.getValues();
This will load the entire range in one fell swoop into a JavaScript array and of course it would be nice if you can filter out unwanted data from the array and then put it into your current sheet at a desired range. Note that the range sizes have to be exact matches and also please realize that ranges start from 1 and arrays start from 0 so that can cause you some grief. Also let me add a few caveats that I've run into.
If your dealing with a one row or one column range array then you have to get the array's in the correct form. I tried writing them here but the Stack Overflow text converter keeps messing them up so I'd recommend you go to my reference on that issue here.
If you've coded in JavaScript in the past I'm guessing that you'll have no problem coming up to speed with Google Apps Scripting with the new documentation and an occasional visit to Stack Overflow for a question or two. I've gotten some great answers here from other users. If you need a JavaScript reference here's one that I use.
You are probably best off using a WebApp served from Google Apps Script for the UI which I'd be happy to help with if you had some sample data. If you wanted to still use the sheets, then you could replace the importRanges with some Google Apps Script function that runs every 10 minutes or so to keep the UI sheet updated. It should speed up load times. Something like this would work for you:
function importSheetA() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var database = SpreadsheetApp.openByUrl("DATABASE_A_URL");
var dataToCopy = database.getSheetByName("DATABASE_A_SHEET_NAME").getDataRange().getValues();
var copyToSheet = ss.getSheetByName("UI_SHEET_NAME");
var copyData = copyToSheet.clearContents().getRange(1, 1, dataToCopy.length, dataToCopy[0].length).setValues(dataToCopy);
}
I'm very new at this and I think I'm trying to do something a little complicated. Ultimately I'm looking to do the following: I would like to have a spreadsheet that upon a submit button does the following, sends spreadsheet to a specified email address, then increases a specified cell number by 1, then clears data that was entered in specific cells.
I have figured out how to increase a cell on a button push that's as far as I have gotten. Any chance someone would be able to point me in the right direction?
For your emailing you want to use MailApp.sendEmail()
The PDF conversion mentioned in the subject line is also pretty easy to use Spreadsheet.getBlob() or if you want to be a bit more verbose Spreadsheet.getAs('application/pdf')
Generally the GoogleAPI is pretty good at explaining a lot of the detail on how to connect to the google libraries
https://support.google.com/docs/answer/91588?hl=en
I have a Sheet where the the cells are filled in with data that is pulled via Apps Script, which they get from a website. Sometimes they pull in the exact same data, sometimes not. On the old Sheets version I use to be able to get emails when the data only "changes" to a different value. Now with the new Sheets, I get an email when new data is pasted into the cells, even though its the exact same data......and, I can't set it to look at ranges anymore, only the entire document. Is there an easy way to watch cells for when the data changes, and then email myself?
This looks a lot like what you're trying to do.
For checking whether the value has truly changed after the edit, this gives you all the necessary information about it. Hence, you would know whether the new value is the same one or not. Implementing the "workaround" talked about in the second link, I was able to compare and send an email to myself if the value changed. Initiate an onEdit trigger that goes off for your onEdit function which uses these lines after all the checks in place have passed.
var email = "xyz#whatever.com";
MailApp.sendEmail(email, "TriggerMail", "A change has occurred in the Sheet");
NOTE: This only sends you a "notification" sort of an email but you can even include the changed values in the email easily by just following this tutorial.
I am new to google apps scripts and I am following the tutorial at https://developers.google.com/apps-script/articles/sites_tutorial and when I run the myContact function from step 1, no contact info is populated into my spreadsheet.
I have a group created called AZ_Pilot, and I have the myContact function set up as follows:
function myContact() {
var contacts = ContactsApp.findContactGroup("AZ_Pilot").getContacts();
SpreadsheetApp.getActiveRange().setValue(contacts[0].getPrimaryEmail());
}
The script runs with no errors, but nothing is updated within the spreadsheet. It's a bit embarrassing to be stumped at step 1, but here we are.
You are using getActiveRange() which is the range which is currently under selection in the spreadsheet. By default, it is the first cell in the spreadsheet. Maybe you have a different cell selected and therefore, the email might be written to a different cell. Try keeping the first cell in focus and running the function again.
Also, you haven't mentioned whether or not there are any contacts in the group you created :)
I was adding some additional logging information, and it just started working correctly with no change to the functional code. Not sure what happened there.