Send This Google Sheet to Email Script

122 views
Skip to first unread message

Nathan Smith

unread,
Feb 25, 2022, 1:18:38 AM2/25/22
to Google Apps Script Community
I am an assistant principal with some knowledge of sheet scripts.  What I need is for teachers to be able to make a copy of a sheet from a link I share with them, fill out the fields, and click send.  Then it needs to send that sheet to me via email.  I am trying to get us out of paper discipline referrals.  I know I could do this with a Google form, however I want it to look more like the paper forms we use, and I want them to be able to start one, edit it, and send it later.  They might have several open for different students.  Does anyone have a script for this? 

I know this script will send it, but if they make a copy of it, the URL changes and then the script isn't send the copy of the form to me.
function sendemail() {
MailApp.sendemail("myemail", "Discipline Referral", "A discipline referral has been assigned to a Fuller Student. View it here: https://docs.google.com/spreadsheets/d/1iEoUfFBb9VeaW5QPE02VAcWw8JUdFTbCB9II6RlPp1U/edit#gid=0");
}

Irfan Khan

unread,
Feb 25, 2022, 4:04:04 AM2/25/22
to Google Apps Script Community
You want to get PDF of the copy?

Irfan Khan

unread,
Feb 25, 2022, 4:04:26 AM2/25/22
to Google Apps Script Community
Here is the steps you've to follow to do it, if you want to get PDF copy of sheet when user click on Send button:-

function sendemail()  {
  const ss = SpreadsheetApp.getActiveSpreadsheet;
  MailApp.sendEmail(' your email ID type here ', ' Enter Subject Here ', ' Body Emaiil Message here ', {
    name: '
Discipline Referral',
    attachments: [SpreadsheetApp.getActiveSpreadsheet().getAs(MimeType.PDF).setName("Discipline Referral Response")]
  });
}



  1. Add this script above in your original sheet.
  2. Right click on Send Button and assign script sendemail to it, so whenever user click the button particular script run.
  3. add "/copy "  at end of original url of sheet, so that when user access it, it take them to create a copy of the sheet. Just like this :-  https://docs.google.com/spreadsheets/d/1iEoUfFBb9VeaW5QPE02VAcWw8JUdFTbCB9II6RlPp1U/copy
  4. Now whenever user click the copy the sheet through URL on Step 3, the original script copy with it.
  5. Please keep note that, when user clicks the button for the first time, they have to authorize the script first on first run, after completing to all the necessary authorization step, when user clicks the button second time, it will send the email with pdf copy of sheet attached with it.
 Thanks
 Irfan Khan

On Friday, February 25, 2022 at 11:48:38 AM UTC+5:30 n.s...@aubreyisd.net wrote:

Sandi Berg

unread,
Feb 25, 2022, 10:51:38 AM2/25/22
to google-apps-sc...@googlegroups.com
Someone more knowledgable will probably have a better idea but this is what I would do.

Make a private addon that your school has access to.

The teacher would open a blank file and run the addon.The addon copies this file in to it and renames the file. The teacher would fill it out and then use the addon to send you the link.

This way, you don't have to worry about cooying the script.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/d51449e6-a05f-4128-9868-cecf3098a26cn%40googlegroups.com.

CBMServices Web

unread,
Feb 25, 2022, 12:23:08 PM2/25/22
to google-apps-sc...@googlegroups.com
Nathan,

I would suggest you look at a Webapp with an HTML form instead of using copying spreadsheets for this. Having a script attached to a spreadsheet means it would need to be authorized by each teacher for them to be able to run it. Also when you copy a spreadsheet, the new sheet will have to be re-authorized. 

In the end you will wind up with many spreadsheets in your folder with no easy way to search through them.

Having a form (whether Google Forms or a Webapp with HTML) allows you to record the data in one spreadsheet which will condense info and allow you to easily search and manage the data.

George

--

Paul Armstrong

unread,
Feb 26, 2022, 3:32:37 PM2/26/22
to Google Apps Script Community
Hi
The add-on and other asp-script solutions will be more elegant.
But you can just replace the /edit part of the URL with /copy and send then link, thus, https://docs.google.com/spreadsheets/d/1iEoUfFBb9VeaW5QPE02VAcWw8JUdFTbCB9II6RlPp1U/copy 

Reply all
Reply to author
Forward
0 new messages