Google form inserts sheet row in unexpected location - google-apps-script

I am having a strange issue regarding in which row of a linked sheet a google form places a new form row. Normally, each form submit adds a row to the sheet, starting with row 2 (row 1 is the header), as expected. If I delete all the rows in the sheet, form submits restart at row 2, as expected. But, now suppose I manually populate say the first 10 rows of the form (again, leaving row 1 as the header, so rows 2-11). Now when I do a form submit, I would expect row 12 to be added to and so on but instead, form starts at row 2 and wipes out my pre-populated row data. It seems that the form and the sheet have an internal "next row number" that is not based on the actual contents of the sheet. Can anyone shed any light one this?

I run into same problem. And found solution (after 2 hours of digging, where is the problem)
You need to use a function
sheet.insertRowsBefore(rowIndex, numberOfRowsToBeInserted)
first to create new rows (space) for your data and AFTER add your data to those created rows.
You can add new rows manually in google sheets of course - it works the same.
Explanation: There is an internal form property which holds a row index where a new form submissions will goes after a form submit.
When you only fill data, the index for new form submissions stays at previous position, so it rewrites your (any) data in cells.
Expect similar behavior when deleting a row data - if you delete only values (by delete key for. eg), then there will stay empty row when new form submission appears. Again you need to use function sheet.deleteRow(index) to delete data and change index of new row for new submissions.

Sounds like you are using the getActiveCell() or getActiveRange() method to find the last row. Whereas, you should be using getDataRange() method to get the last row and columns. getActiveCell() or getActiveRange() methods point to the location of the cursor on the Spreadsheet. Hence, if at the time it was at Row 1 - Col2, that's where it'll insert your info. Refer to this documentation for more information.

This happens by design so that form submissions never overwrite user inserted data. This is well demonstrated in this response[1].
I believe you could resolve problems if you create a script to insert your older data using the createResponse() method[2].
[1] https://support.google.com/docs/thread/10244473/google-forms-inserting-at-top-of-sheet?hl=en
[2] https://developers.google.com/apps-script/reference/forms/form#createResponse()

Related

Data entry form responses directly to a template

I have created a data entry form in Google Sheets, and would now like the data to be placed in my templates cells automatically. The user fills out a form, and ideally the answers would fill out the template and execute the calculations automatically. Is this possible?
My key questions are to
create a new tab with a template for each new data entry (results in a row in the data tab)
place entry-values to the tab to execute the calculations
I can also create many duplicate tabs of the template and place each answer to the specific cell manually, but I don't know how many entries there will be.
I have tried to create a new tab with new entries, but the tab is missing my template. I tried to link answers to specific cells, but did not know how.
If I understood correctly, you are using Google Forms to collect data and store the responses in a Google Sheet.
If that is correct, the best way to manage that input data adding calculations or other extra fields is to use a different tab.
F.e, if your form is collecting responses in tab "Form A", then you need to
Create another tab (let's say "curated A responses")
Import the data from "Form A" into the second tab
Add more fields, calculations, charts... whatever you need.
The simplest way to perform step 2 y using ='Form A'!A:A for column A and so on.
You write that into the first column of the second tab and it will populate existing and new values automatically.

Get multiple values from onChange row event

Am stuck. Have looked high and low for a method to pull multiple edited values from a google spreadsheet row. Have trawled through the google App Script list of commands. Nothing found.
A form is submitted to a google sheet that can change multiple columns per row per event.
Basically, I have an onChange(e) script that reads the changed row. It is installed and working. I can pull from the changed row single values, row and column details etc. However, despite using a variety of combinations I cannot pull a multiple row changes from a form that updates the row with multiple column changes per row. I have tried array variables all to no avail. It still only pulls a single column change per row. Have also tried A1Notation again to no avail.
Is there any way to pull changes in columns 3, 9, 17 for example?
I am happy to work through the problem if someone can just let me know a single line function command or a way that it is done. Is there something like columnChanges = [ e.source.getXXXXXX().getYYYYYY() ]; that will allow me to pull array variables that have the changed values?
Any help appreciated but I am now desperately stuck with this and prefer to avoid keeping duplicate spreadsheet and then cross checking what has changed between the two.
If you are using a Google Form to submit values into your spreadsheet, then you could use a Form submit trigger instead, and you can easily get all changes out from it.
Also, depending on your script, you might actually be only listening for one of the Edit events, which also triggers Change.
Share your script to get more specific help.

Data entry form (search, add, edit, delete) for more than one row - google sheet

Is there a way to work with data entry for more than one row through a form in Google Sheet or a tool to add, search, modify and delete ?
Maybe the dialog form best for my order
First: Save Data button
Add a button in the form to add more than one data entry row at a time before saving
For example, adding more than one product type for a supplier
Second: When searching
Enter the supplier code in the cell (D3) to call all the supplier data rows from input and output
Third: When modification or deletion after the search
Allow selection to modify or delete a row from the called rows
Example Form
Source of the article
Form Proposal

How to add a button in Google Sheets that Automatically Adds Columns and formulas

I would like to add a script to a button I created in Google Sheets. I would like the button to add a new column before my "Month Loss" column. I would like the new column to copy the formulas and formatting of the column to the left.
This will provide an easy way to track my body measurements and help to determine calculate my body fat percentage.
Here is a link to my sheet: https://docs.google.com/spreadsheets/d/1DP0SQpU16YEfPWoE8IRknoqQWu0wrFagzhLflVOkn8M/edit?usp=sharing
A Pivot Table has been created though script. if you try to programmatically update the range, there is no way either because named ranges need to be deleted then re-added which causes on the pivot.
if you are adding the new row by script, do not append it to the end. instead keep a fake row at the end and insert the new row just before it. your range (named or not) will update.
Even for the google forms case you might get it to work by pre-adding all blank rows to the response sheet and make the named range include the blank ones too.
Found this Stack Overflow ticket discuss about Pivot Table, you may also check the solution offered by the community: Google Spreadsheet Pivot Table Range Update Using Scripts

Google Sheets Pivot Table Not Updating

I have a google app script which submits info to an organized sheet and would like to create a pivot table with the all information in the sheet. I can do this, but whenever I submit a new row of data to the sheet, it is not automatically included in the pivot table. I have to manually change the range of the pivot table every time I submit a new row of data. Is there any way I can make the sheet/pivot table automatically include the new row of data?
I worked around this issue by only specifying the column range.
For example, if you have row data in columns A to F, set the range of the pivot table to SHEET!A:F
If you add rows now, the new data in those columns will be added to the pivot table.
There is a way. I did exactly that 3 years ago on Sheets.
If you are submitting the new rows using Google Forms, then there is no way.
If you try to programmatically update the range, there is no way either because named ranges need to be deleted then re-added, causing #REF on the pivot.
Now for the good part: If you are adding the new row with a script, do not append it to the end. Instead, keep a fake row at the end (with zero values so pivot is not affected) and insert the new row just before it. Your range (named or not) will update.
Even for the Google Forms case, you might get it to work by pre-adding all blank rows to the response sheet and make the named range include the blank ones too.
I encountered the same problem with the Google Sheet linked to a form. How I solved it:
Edit the Pivot table range to include the empty row after the last row in your sheet.
If your pivot table data range is 'Sheet Name'!A1:S100, change it to 'Sheet Name'!A1:S101.
Add a filter to your pivot table for a column (present in the data range) that will never be blank and set the condition for this column - 'Is not empty'
If you have a column 'Timestamp' (and you're sure it will never be empty), then add this column to the filter, select 'filter by condition' and set the condition to 'Is not empty'.
These steps will filter out the last (empty) row. When you will add a new row to your data, the pivot table will update automatically and you won't have to update the data range again.
In my case what was interfering were the fields in the Pivot's Filters section (highlighted in red below).
Make sure you test without any filters... see if it works. Then add your filters one by one and play with the pivot. Probably the filter(s) is\are influencing the pivot to not update.