How to write a script to create and populate new spreadsheets from a master document? - google-sheets

I would like to create a pupil progress sheet for each of my pupils that is held in my gdrive and is owned by me (Teacher).This spreadsheet would use import range to pull test data from the 'Class sheet'. The pupil would be able to view their file but not make changes, or make a copy of the file so that they can make changes!).
This I can do manually but doing this for a class of 30 (let alone the 10 classes I have!) would be tedious in the extreme. I would imagine that a script might be able to automate much of this and I was wondering if there are any showstoppers in the list of requirements below before investigating further.
Is it possible to create a script that does the following from a MASTER SHEET (below):
A B C D
1 ID NAME EMAIL
2 1 sample sample#gmail.com
3 2 sample2 sample2#gmail.com
1) Run through the list above and create a duplicate of a separate template Google Sheets file for each person in Column C.
2) Rename the sheet to their name using column C
3) Populate a single cell (A1) within the new spreadsheets with their ID (Column B)
4) Share with the email (Column D) allowing VIEWING only and disabling copying the file etc.

Yes, you can create a "Master" document, only readable and not editable by anyone else but you. That document can be accessible to all your students after you share it with a "public link" to view (not to edit).
With the help of Google's SpreadSheet, you can create a file with different questions for instance, and run a script to generate different types of tests, but this might require a little of knowledge of Javascript. You can learn how to make Google drive scripts from tutorials.
For me, the creation of automatic named files for every student, and send emails automatically is not a great idea, but yes you can do it and there are tutorials on how to send emails from a Spreadsheet.
The best option is to just give a link to your students.
Preferably, after you create a sharing link from Google Drive, you should make the link as short as possible, by using a free service like the site bit.ly where any huge and hard to remember old link, can be shortened to something more easy to use like bit.ly/TomTests_Oct2016.
You can also consider to use Khan Academy if it fits your needs, since you are a teacher. This is definitely one good platform to evaluate students progress, with a lot of free content (if not everything).

Related

How can I link to Google Sheet from Google Form? (Exploring Make a Copy feature, but I need it to be shared with the original owner)

I'm posting here because I'm hoping someone can help me edit the link to a google sheet. I haven't been able to find the answer online, but I'm hoping maybe someone understands how the link works better than I and can give me an answer.
I've been tasked with updating the application for funding (from a non-profit) to include a budget category. The application is in Google Forms, but there's no way to insert a table into the form for an applicant to fill out. I created the budget outline in a Google Sheet, but now I'm trying to find the best solution to create an individual link within the form that will lead them to the budget document. Essentially, I'm hoping the applicant can fill out the form, and when they reach the section about their budget, I want them to click the link to the google sheet, have it make a copy, but have the copy be shared with the organization's google account so we can see it when they submit their application.
I've experiment with the forced copy feature (editing the shared link by google), but when I test it from a different google account than the owner, it tells me I have to request permission. The share settings are set to allow anyone with the link to access, so I don't understand why it's asking me to request permission when I open the force copy link. This isn't going to work because the applicants need to access it when applying, and we can't have them waiting for us to accept the request every time.
I'm sure there could be a few solutions, so I'm open to any advice. The only other solution I can possibly think of is creating individual links for each applicant, if there's a way to automate that?
I recognize there could be a solution where I ask the applicant to download the file and re-upload, or share it themselves, but our applicants are not native english speakers and they are often non very comfortable with technology, so I want to automate the process as much as possible.
To summarize: The applicant should be able to
Fill out the google form
Receive an individual copy of the budget document (from google sheets) to fill out.
The budget document must be shared with the original owner so we can see it and see how it relates to the rest of their application.
Thank you for your consideration!
A solution for your use-case would be to make use of Apps Script.
Apps Script is a powerful development platform which can be used to build web apps and automate tasks. What makes it special is the fact that it is easy to use and to create applications that integrate with G Suite.
Taking this into account, you can create a script which will create a copy of the document whenever a new form submission is made and add the permissions needed for the user. Essentially, you will be the one owning the copy of the sheet as well and the candidates will have edit permissions.
Therefore, the script will end up looking something similar to this:
Code
function onFormSubmit() {
let sheetId = 'ORIGINAL_SPREADSHEET_ID';
let form = FormApp.getActiveForm();
let responses = form.getResponses();
let n = responses.length;
let currentUser = form.getResponse(responses[n-1].getId()).getRespondentEmail();
let newSpreadsheet = SpreadsheetApp.openById(sheetId).copy("Sheet copy for " + currentUser);
let newSpreadsheetId = newSpreadsheet.getId();
DriveApp.getFileById(newSpreadsheetId).addEditor(currentUser);
}
Explanation
The above snippet makes use of the Apps Script's onFormSubmit installable trigger. Basically, whenever a new form submission is sent, the code above will run. The code will retrieve the last response which was submitted and get the user's email address by making use of the getRespondentEmail method. Afterwards, a copy of the original spreadsheet will get created and shared with the editor permission with the user who just submitted the form. Adding the permission is done by making use of the addEditor method from the DriveApp parent class. As for the user accessing the copy of the spreadsheet, this is easily done as the user will end up receiving an email telling them that a spreadsheet has been shared with them.
Setup
You will have to have the Collect emails option checked for the form;
Open the three dots icon and click on Script Editor;
Once you open the script editor, input the code from above and do not forget to modify the sheetId such that it matches the id of your original spreadsheet that you want to share.
Install the onFormSubmit trigger by going to the Triggers page and create a new trigger with the following options:
Send the URL form to the candidates and wait for submission to be sent.
Reference
Google Apps Script;
Apps Script Installable Triggers;
Apps Script SpreadsheetApp Class;
Apps Script FormApp Class;
Apps Script DriveApp Class.

Trying to create a custom process that shares specific information

I work for a high school that has a regular four day school week and calls students in for "Reteach and Enrichment" on Fridays. To help organize the schedule for this, the school has created a Google Sheet that lists all of the student names and allows the teachers to fill in what time they would like any particular student to come to their class that Friday. This is working fine for the school's organizational side, but informing students of their assignments is currently a bit of a nightmare.
Because students will try to get out of anything, we have to have documentation indicating that we "told the students they need to come to our classroom on Friday". This is currently done in the form of giving a student a slip of carbon copy paper informing them of the time they are called in. As you can imagine, this is extremely time-consuming and full of holes since the students can throw the paper away or claim "they never got the paper" even though we've got a second copy of that paper indicating that it was filled out. But I digress.
The reason I'm writing to you fellow internet people is that I've taken on the task of trying to streamline the process of notifying the students of their schedules for Fridays. Because of privacy issues, we cannot give the students read-only access to the master list for Fridays, but I'm looking for a way to inform them of their specific information. My first thought was to write a program that would make a google sheet of each line on the master sheet, and share that sheet with the student whose information was on that line. This seems painful to set up and manage though and will lead to a lot of documents in google drives that are only needed for a week. The second problem is that I'm not sure what type of application I could use to run a program that would need to be able to access one google sheet, copy information from it, create a new google sheet, paste the copied information, gather the correct account the information needs to be shared with, and share read access to the new sheet that was created. I was thinking of using Auto Hotkey, but I know there's got to be a better solution to this problem.
If you have any suggestions for a different approach, please let me know. I believe that I can get an automated process to do what I described above if I can get the process down to a rote set of steps to take for each line on the original google sheet. But I'm hoping there's a way to do like an XLookup or Vlookup from a new sheet that references the original or something.

I want to check information contained in a Google sheet, as the respondent is completing a form

We are using forms to allow people (staff) to book equipment out of a store, self service. We record who took what, and when they book it back in. They are asked if the tool condition is good, and if not, are taken to another part of the form to select a fault category. I record this information in the linked sheet.
so my question is can I read the information in the "fault" column of the linked sheet for that item ID, and generate a message to the form user such as "This item has been reported as faulty - please do not use it!" etc etc
If I could script the form so that it scans the linked sheet in the relevant column / row for the item they are trying to scan out, and then warn them that is has an entry in the "Fault" column, that would be perfect. Ideally as they scan the barcode of the item they are taking, before submitting the form, but after submit would be fine too.
I have searched widely and not yet found a solution
Since the only triggers which are available for Forms are the onOpen, onInstall and onFormSubmit, this cannot be done directly.
Possible solutions
1. You can develop your own form
This can be done by using Apps Script & HTML & JavaScript and creating your own Sheets add-on which will interract with the sheet you have in order to check the status of the tool.
2. You can programmatically update either the question name or the form description in order to include the accepted values for the question regarding the tools.
This can be done by creating a script attached to the sheet and using the onEdit(). So whenever a change is made in the tools section for example, this new data can be gathered as a string and update the fields to contain the updated values for the tools.
Reference
Apps Script Simple Triggers;
Extending G Suite with Add-ons.

Sharing a created Google form with linked sheet for others to use

I have created several systems with Google Forms (and linked sheets) to log services provided and timekeeping. I would like to share these systems with other people to use as a template for their own data. Is there a way to easily do this keeping my formula's intact?
Successfully: I have found a way to share the form only as a template by copying the URL into an emailed hyperlink changing the ending from edit to copy.
Cumbersome but ok Migrant Service Log: This method does not seem to work entirely for spreadsheets. It still asks me to give them access to the original document. I can set access on the original to view only and limit the time to one day.
Unsuccessful Clock In/Out: The new "copy" of the spreadsheet is not automatically linked with new "copy" of the Forms so it does not update when a new response is added. I must link it in form. This becomes more of an issue with my sheets that have formulas based on these responses. It is now necessary for each new user to manually link and rename the sheets to make them function correctly.
Clock In/Out System (attendance purposes)
Clock In Form
Clock Out Form
MSA Sheet
Attendance Office Sheet
Migrant Service Log (team communication purposes)
Migrant Service Log Form
Migrant Service Log Sheet
I would like for them to all be user-friendly and easily shared while keeping everything confidential to the user.
if you want to keep your formulas as a secret you can set up the 2nd spreadsheet and use IMPORTRANGE formula to get data over and then just simply link the 2nd spreadsheet somewhere on the end of the form.

Can I make a summary of only selected data?

I want to select only certain rows and columns and use the same "summary of responses" feature but for limited data rather than all of it. Is this possible?
The report is with ALL DATA from this sheet - I want the exact same output but with only certain email addresses.
Google Form: bit.ly/bilvalchal_results
If I have a google spreadsheet can I make a summary of only selected data?
Yes, but I think your Title may be misleading. I thought at first you wanted any summary but now believe you want the specific format provided by Form > Show summary of responses, and that is quite different.
Is this possible?
In essence, I think not. For example, in Excel it is easy enough to avoid charting data simply by hiding it. That seems not to work here. Even deleting data in the Form responses sheet does not change the Summary of responses.
This presumably because both the Form responses sheet and the Summary of responses are distinct views of server-side data. I doubt there is a means for a user to control the code that drives the Summary of responses, whose data is gathered from the individual form submissions (as is the data shown in the responses sheet). Submissions have spawned both the sheet and the Summary but the two are independent of one another.
On the other hand.
As mentioned by #zeroCoder, equivalent results might be obtained by a user though it would seem with a considerable effort. A script may be required to set the chart type to use for each question by question type (if to avoid an ad-hoc basis, Form by Form). Once the type appropriate to each column has been determined it would be a little tedious but not difficult to create the corresponding chart. Adjusting the formatting, scales etc to match that of Summary of responses would also be tedious but with a script would not need to be purpose-built for each Form individually.
That said, I hope I am crassly mistaken and that actually it is quite easy. I suspect however you would have heard by now were that so.
Another option is to use the Awesome Tables web app. It allows filtering of your data (and more). It is available as a gadget on Google Sites.
So this doesn't use the built in feature exactly but it does the trick.
Take your sheet with all the rows and figure out which columns you want to show.
Create a new sheet called preview or whatever.
in the top cell for each column reference the row from the responses sheet like this ={'Form Responses 1'!A:A}
Then hit File>Publish to web and chose to publish your Preview sheet only.
Get your shared link (shorten it if you must).
Post that url in your form only and presto.
You win!
You need to use pivot tables here are some tutorials on how to use them:
How to create a pivot table report
Summarize your data with pivot tables

Resources