merge two google forms data into the one spreadsheet - google-apps-script

I want to create application which takes two different google forms data into the one spreadsheet and having two different sheets there on a single spreadsheet with the help of google apps script.
I've searched over a lot but hadn't find any satisfactory solution. Can anyone tell me that is that possible to acheive with google-apps-scripts?
Sorry, I don't have any piece of code this time.

It is impossible to insert data of two Google Forms directly to a single spreadsheet using GAS without involving another two spreadsheets, because now the Forms are able to deploy data only to own spreadsheet and GAS has no any service to access to the Forms.
There is a workaround which merges the Forms spreadsheets to a single spreadsheet using the ImportRange function (see bellow paragraph) but seems it is not suitable for you.
The spreadsheets have the ImportRange function which permits to import a source spreadsheet range to a destination spreadsheet, for instance, there is a task to import spreadsheet_1 columns A, B, C of Sheet1 and spreadsheet_2 columns B, C of the Sheet2 to spreadsheet_0 columns F, G, H, I and J. To achieve it is necessary to place to the spreadsheet_0 cell F1 the =ImportRange("spreadsheet_1_key", "Sheet1!A:C") formula and the cell I1 should contain the =ImportRange("spreadsheet_2_key", "Sheet2!B:C") formula.

For anyone who ends up at this question, looking for some general knowledge, you can change the form destination. In the form editor, choose RESPONSES, CHANGE RESPONSE DESTINATION. The form responses can be sent to another spreadsheet. I'm not sure if this is a capability that didn't exist when this question was first asked, but for anyone doing a general search, you might end up here.

Related

How to solve the limitation of IMPORTRANGE formula in google sheet?

I have 50 google sheet files for 50 students. They need to key in their answers in their own google sheet file when they are asked to do so. I have a main google sheet to consolidate their data by using IMPORTRANGE formula. This is my formula:
=QUERY({IMPORTRANGE(...);IMPORTRANGE(...);IMPORTRANGE(...);...},"Select * where Col1 is not null")
I will have 50 IMPORTRANGE in the formula. So as expected, the main google sheet is very lag when the 50 students start to key in their answers at the same time. Sometimes, the formula will show #Value when all the students started to answer the questions at their own google sheet file. I need to keep refreshing the main google sheet so that the data will come out, but it will disappear again in a short while then I need to refresh it again (although it will settle down once most of the students finished answering the questions).
I know that using IMPORTRANGE is really not an efficient way to consolidate their answers in main google sheet file but I don't have other better way.
I tried to write a script so that they can send in their data by clicking the button assigned with the script. However, all the students need to go through the authorization process when they run the script for the first time. They don't know how to proceed when they saw the authorization process (not very good in using computer).
May I know is there any ways or tricks that I can use to solve the IMPORTRANGE issue? Or there are some way to write the script where we are not required to go through the authorization process when we run the script for the first time?
Hope to get some advice and help on this as I couldn't find a better way from Google already. Any help will be greatly appreciated!
If I understood correctly what you are looking is that your spreadsheet show in real-time the data being entered simultaneously on 50 different spreadsheets. I'm afraid that Google Sheets is not the right tool for what you are trying to do the way that you are trying to do it. Basically you have two options : change it or use a different tool.
It's not a good idea to have and array of multiple IMPORTRANGE functions that are being edited simultaneously because while the official docs says that IMPORTRANGE functions are updated every 30 minutes when the source and the spreadsheet having formula are opened at the same time the import is done practically immediately and could happen multiple times during the recalculation making causing it to start over an over again.
Replacing the above array by script might help only if you are open to not have the destination spreadsheet updated on real time as scripts are slow.
Replacing the above array by a program that uses the Google Sheets API also might help only if you are open to not have the destination spreadsheet updated on real time as the spreadsheet refresh.
Regarding running a script without requiring authorization that is only possible when using simple triggers and / or removing all the scopes that require authorization to run. Please bear in mind that you might create installable triggers to run other using the authorization of the user who creates them.
Related
Combining multiple spreadsheets in one using IMPORTRANGE
Why do two users sometimes see different values from importrange?
Multiple IMPORTRANGE
Using that many IMPORTRANGE formulas is definitely a bad idea. What I'd suggest you to do:
keep a list of all your student spreadsheet in your main document
write a script that will browse through all of the spreadsheets from that list and copy/paste values into your main document
create a time based trigger that will run the script every X minutes (or hours), depending on how accurate you want the results to be
This is a simple solution, but efficient. Depending on the amount of data and number of students/spreadsheets you may consider other solutions (like writing a cloud function that will do the same as the script) but I think this will work for your use case

charts from one google spreadsheet to another dynamically

Google spreadsheet A with "sheet 1" - Master spreadsheet
Google spreadsheet B with "sheet 1"
There are charts in sheet B with source data in it. I want to import the chart to master spreadsheet B in such a way that, when the chart changes in sheet B, it should dynamically change in master sheet A too.
After a lot of research, I was able to find below:
Importrange - imports the data only, and not charts
copying the chart itself and pasting it to master sheet A, but it doesn't get changed when the chart is changing dynamically in sheet B.
publishing the chart and inserting the URL as an image - this doesn't work if the master sheet A is google spreadsheet, but works for google docs, slides, etc. (correct me if I am wrong, as I tried and threw me an error)
For ease of explanation, I have given only two spreadsheets as an example. In the real case, I have one mastersheet, and 6 separate spreadsheets.
Any alternative suggested, or help is highly appreciated. Thanks
Don't know your task but I found the answer to your question by using IMPORTAGE for data, then show the chart and hide the list where the data are shown

Google Scripts Generated VLOOKUP Formula Does not Calculate Properly

I am writing formulas to cells programmatically.
The following line of code:
formulaCells.setFormulaR1C1('=iferror(VLOOKUP(R[0]C[3],AutoCat!A:B,2,FALSE),"Requires Category")');
Adequately writes this formula into all the cells in the target Google Sheets file represented by formulaCells
=iferror(VLOOKUP(D2,AutoCat!A:B,2,FALSE),"Requires Category")
But the problem is that the formula defaults to the error flag "Requires Category" when it is written by Google Scripts, but if I write the very same formula manually into Google Sheets, the actual item identified by the VLOOKUP results.
This is so frustrating!
If I hover over the Google Script generated formula, the true solution from the VLOOKUP even appears in the flyover, but for some reason, does not appear in the cell.
Please help! Why will a Google Scripts generated formula not calculate properly wen the same formula entered manually will?
OK, after thinking I'd exhausted my mental resources on this, I tried one last thing, and it actually worked.
For some unknown reason, though the formula is accurate, Google Scripts generated formulas do not play well with a VLOOKUP which searches an unlimited range for a solution. So even though the VLOOKUP was finding the correct solution, it was not displaying it as the formula result.
I fixed this by creating in the Google Sheets file a named range of the data the VLOOKUP would search called AutoCategory, and then inserted that named range into the Google Scripts generated formula, and BOOM! the formula started working.
Here is the final code in Scripts:
formulaCells.setFormulaR1C1('=iferror(VLOOKUP(R[0]C[3],AutoCategory,2,FALSE),"Requires Category")');
And here is the final formula which is generated in Google Sheets:
=iferror(VLOOKUP(D2,AutoCategory,2,FALSE),"Requires Category")
setFormulaR1C1 requires R1C1 notation, which you provided with R[0]C[3], but AutoCat!A:B is A1 notation.
You could switch to setFormula() and pass in only A1 notation, but I think that using named ranges is a very good practice when combined with Google Apps Script.

Fetch values from multiple sheets Google sheets

I'm trying to find an Employee ID from the attendance which spans multiple sheets and pull the timestamp into a single sheet.
The Google sheet has multiple sheets in it. There are individual sheets for every working day:
Each attendance sheet has two columns. In order to know all the times of the employee's login I want to pull in all the occurrences of the employee ID from all the sheets and along with its timestamp to the Consolidation sheet: .
I've done a similar thing in Excel and guess can be done in Google sheet using Google Apps script.
It would be helpful if someone can guide me to a built-in or custom function in google sheets.
I'll help you with a basic outline, some advice, and some resources to help, but don't expect me to write the whole thing.
Step 1 - Create a custom menu option
You'll want to be able to access you script from the spreadsheet. You can accomplish this by creating a custom menu option. Here's an article by google on custom menus.
Although google uses the simple trigger onOpen, I've found installable triggers to be more reliable.
Step 2 - Get user input
It would be nice to be prompted for the id of the employee and have the script work it's magic. Here is an article by google on dialogs and sidebars that discusses how to get user input for a script.
Step 3 - Read and write data from the spreadsheet
You can access spreadsheeet data with the SpreadsheetApp. When calling your script from a custom menu, you can use SpreadsheetApp.getActiveSpreadsheet; however, if you want to test your code in the script editor, there is no "active spreadsheet", so use SpreadsheetApp.openById instead.
With access to the spreadsheet, you can call:
spreadsheet.getSheetByName("name").getRange(1, 1, 2, 2).getValues();
spreadsheet.getSheetByName("name").getRange(1, 1, 2, 2).setValues([[1, 2], [3, 4]]);
Note that getValues and setValues work with 2-dimensional arrays
WARNING - As usual, I/O takes a lot of processing time so avoid superfluously calling getRange().XetValues, this google article about appscript best practices goes into more detail. Also, if you have a LOT of attendance sheets, then you may want to consider condensing them into one.
Step 4 - Get the appropriate sheets
You'll need someway to distinguish which sheets in the spreadsheet are attendance sheets:
function isAttendanceSheet(sheet) {
return /Magical regex/.test(sheet.getName);
}
var sheets = spreadsheet.getSheets().filter(isAttendanceSheet);
Come up with the magical regex that works for you, and this will filter them.
Hope this helps and good luck!

Google script: unprotect a sheet through function when user has no right to do so

I have a spreadsheet with different sheets in Google sheet, 3 users can edit each one a sheet (protections are set, each user can edit only one sheet). They all can execute a google script function that writes what they edited in a summary sheet. I don't want anyone to be abble to edit the summary sheet, so I set myself as the only available editor.
So my problem is to authorize the 3 users, only through the google script function, to write in the summary sheet. I tried to use the following function :
var unprotected = summarySheet.getRange('G3:G10');
protection.setUnprotectedRanges([unprotected]);
but since the users are not allowed to edit the summary sheet, and since the function is run with the active user, so they can't give themselves the right to unprotect a range in the summary sheet... Do you know how to workaround this problem?
Thanks a lot!
I see two script-based choices, one easy and one quite hard, and one sheet-based choice, that is easiest:
Easy:
You run the "summarize" script instead of them or, you set the summarize script run on a trigger out of your account. Then you actually leave protections alone. You could set the summarize script to run on open with error catching if the user doesn't have the necessary authority to unprotect the summary sheet and/or write to the summary sheet.
Hard:
When they run the "summarize" script it calls a published standalone script that has been given the authorization to make the necessary protection changes. I'll be honest, I wouldn't be able to code this but have seen/heard of similar implementations.
Easiest:
Finally, I want to make sure you've considered having the summary sheet itself contain the necessary formulas, parsing, etc. to summarize data from the other sheets without any need of scripts for this aspect of the sheet. The sheet could call custom functions as needed if the parsing or other summarization functionality is beyond built-in functions' capabilities. The sheet could stay fully protected and update itself in real time as users enter data (no need for users to trigger the summary creation, unless spreadsheet settings have auto-recalculate turned off).
Edited to add: put in A1 of Summary sheet something like:
=summarize()
And have that custom function return a 2-dimensional array of the summarized data.