Google spreadsheets auto fill formula with form submission - google-apps-script

I am trying to get my Google form submissions set up so I can produce a PDF with Auto Crat with the right information since my form has yes and no questions.
I need 4 different columns to auto fill with my different but similar formula below as my first sheet is filled using IMPORTRANGE from my Form submissions master sheet. If there is an easier way to do all this please let me know since I am really new to Google formulas.
=if(Sheet1!P3="Yes", (CONCATENATE("My yes answer "&CHAR(10)&CHAR(10)&"<b>Employee name:</b> "&Sheet1!Q3&CHAR(10)&"<b>Location (room number where the employee will be during the emergency):</b> "&Sheet1!R3&CHAR(10)&"<b>Telephone number (room where the employee will be during the emergency):</b> "&Sheet1!S3&CHAR(10)&"<b>Critical operation:</b> "&Sheet1!T3)), "it is the no response")
Here is the Master
Here is the two sheets I am using. The first pulls in the information and the second sheet is where I use my formulas.

I was able to get an add-on to sheets called copyDown to copy the formula down the rows for me. This helped me to keep it all on one sheet instead of having two sheets so I could use AutoCrat for compiling my PDF correctly. Thank you for all the help in solving this issue.

Related

Looking for a script that will add in a blank row after a new value is detected

I work for a small business selling hot wheels and other diecast related products, and we are constantly needing to create lists in google sheets for pre-ordered products. I am looking for a script that will insert a blank row between every customer.
I have already automated everything to organize the data when importing a .CSV file using scripts I've found here, but manually inserting a blank row between each customer is what takes the most time. If more information is needed, just please let me know.
I found a script here that allowed me to auto fill the customers names into the empty cells below until it detects a new value. (when importing .csv, if the customer has multiple items in an order, it doesn't put their name in all cells of the customer column, only the first cell)
I'm probably wrong on this, but it seems like I might be able to adapt this script to recognize when a value is different from the one above, then add a blank row.
I am new to google sheets and scripting. So if possible, please try to explain as simply as you can. Thanks!
Edit:
Link to spreadsheet with data: https://docs.google.com/spreadsheets/d/1W8peYL9kZhtQWdeCPP2uDkmsqy3nL1kVPmgJJq4T_80/edit#gid=2100307022
Edit:
Updated spreadsheet to show input/output examples and added more information to main post
Insert a row into sheet when a new value appears during an edit
function onEdit(e) {
Logger.log(JSON.stringify(e));
e.source.toast('Entry');//debug
const sh = e.range.getSheet();
if(sh.getName() == 'Sheet name' && e.value) {
sh.insertRows(e.range.rowStart);
}
}
onEdit

Copy Adjacent Cells alongside Duplicate Cells

I have a very large Google Sheet spreadsheet that I need help with.
I have a long list of Network Switches that are very often repeated that I am trying to automatically copy the associated SKU into a separate adjacent cell.
My goal was, once the SKU is added the first time, whenever the same switch is added again, it will autopopulate with the same SKU.
For instance, C2461:C2463 are repeated, and once K2461 is populated, would like K2462 & K2463 to follow suit.
Any help would be greatly appreciated!
You can try this formula on Column L (col L will serve as a helper column):
=iferror(arrayformula(VLOOKUP(C2:C,C2:K,9,False)),"")
For now I can't seem to fit the formula without the use of a helper column (so I created a separate sheet for now that will serve as a database for the VLOOKUP formula) but this should get you started.
Sample using a helper spreadsheet (Database):
=iferror(arrayformula(VLOOKUP(Database!A2:A,Database!A2:B,2,False)),"")
Output:

Generating hyperlinks to prepopulate Google form

Context:
I created a Google Sheets/Forms workflow using sequential stages of Google Forms.
Form 1 (public facing) Accepts some data submitted by a public user and saves to Sheet 1.
Internal staff then contacts the submitter by telephone and conduct a more in-depth interview.
Form 2 (internally facing) is used by the interviewer to document
answers to the phone interview.
This question concerns the generation of Form 2 because I am partially pre-populating it with information from Sheet 1 (Form 1 submissions.) The way I figured out was to formulaically generate a URL with appended pre-population arguments e.g. "&entry.NNNNNN=whatever". I copied-down this formula in the last column of Sheet 1. Clicking on the cell and then the generated hyperlink successfully pre-populates Form 2 with data from the respective row of Sheet 1 as intended.
Problem: As soon as a new Form 1 submission is received, a new row is inserted into the Sheet 1 that does NOT contain the desired hyperlink formula in the last column. I would like that to be automatic so the interviewer is not responsible for performing a copy-down before every request for a Form 2.
I have pursued a couple of approaches to automating this:
One thread advised instead of copy-down, to create an arrayformula in the top cell so that it applies to the entire column including newly inserted rows as well. I tried every way I could think of but was unable to get my formula to produce a column of results with arrayformula(). If there is a way to fix this, that would be a satisfactory solution.
=HYPERLINK(CONCATENATE("https://docs.google.com/forms/d/e/XXXXXXXXXXXXXXXX/viewform?usp=pp_url&entry.251357138=",C2,"&entry.966351469=",D2,"&entry.384696201=",E2,"&entry.1366694528=",F2,"&entry.463407115=",M2,"&entry.1557144679=",B2,if(P2,"&entry.1777888516=Email",""),if(O2,"&entry.1777888516=Phone",""),if(H2,"&entry.2110474669=Individual+(Adult)",""),if(I2,"&entry.2110474669=Individual+(Under+18,+Minor)",""),if(J2,"&entry.2110474669=Couple",""),if(K2,"&entry.2110474669=Family",""),if(L2,"&entry.2110474669=Group",""),if(R2,"&entry.1892971721=San+Jose",""),if(S2,"&entry.1892971721=Sunnyvale","")), "Complete Intake")
I tried to create a ModalDialogue and display a script generated hyperlink in it. I used this approach found in this forum. But this did not open any dialog at all and threw no errors (even after hyperlink was removed.) There was no indication of pop-up blocking. Other parts of my script use Browser.msgBox without any pop-up troubles, but I don't think that will pass a hyperlink.
var htmlOutput = HtmlService
.createHtmlOutput('Click to open and prefill intake interview form.')
.setWidth(250) //optional
.setHeight(50); //optional
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Ready to fill intake interview form:');
Using onFormSubmit() and scripting a copydown after a new row has been inserted. But I have been unable to figure out how to identify which row was inserted into Sheet 1. I see some people using lastRow(), but it isn't always inserted into the last row - typically it goes in the middle somewhere.
Request:
Help getting arrayformula to work in my case.
Or help getting ModalDialog to display a script generated hyperlink.
Or help on how to identify the row the Form submission inserted. Or do I just need to make sure the table remains sorted by TimeStamp and then I can use lastrow()?
Suggestion for a cleaner approach to get to the same place (generating a prepopulated Form from a row of data in Sheet 1.)
Thank you for illuminating a path forward.
You should consider using ArrayForumlas to automatically copy down the formula to other rows that have a value in the first column.
Put this formular in row 2 of the column that has the Google Form links.
=ARRAYFORMULA(
IF(ISTEXT(A2:A),
HYPERLINK(
CONCATENATE(
"https://docs.google.com/forms/d/e/XXXXXXXXXXXXXXXX/viewform?usp=pp_url&entry.251357138=",C2:C,"&entry.966351469=",D2:D
)),""))
I wrote a tutorial on copying formulas if you need more examples.
It turned out I was able to successfully employ approach 2, the modalDialog. For some reason no dialog was appearing when I first attempted so I didn't know if there was something fundamental wrong with this approach. I tried again and it worked as shown below so I suppose I just had some typos. Adding target="_blank" was helpful so as to open in a new tab.
var htmlOutput = HtmlService
.createHtmlOutput('Click to open and prefill intake interview form.')
.setWidth(250) //optional
.setHeight(50); //optional
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Ready to fill intake interview form:');

Is there a way to have google form responses to record in sheets depending on what section of the form is filled out?

I made a form with multiple conditional paths and my response sheet is ungodly I could really use some help.
The way I set up the form has a total of 19 sections
Location Dropdown (we have 3)> Machine dropdown (a total of 15)> A Machine Specific measurement section and Submit.
I split the Measurements sections by machine because, I was hoping I could have each section record numbers into separate sheets. This way I could keep each Machine's data on its own google sheet.
So logically I am trying to get MachineX measurements to record sheet X but, Get Machine Y to record In Sheet Y. Is what I'm looking for feasible/ even possible?
I know I can try and organize the form responses into the sheets manually, but I am trying my best to avoid that, cause its gonna take a lot of time out of the week.
Maybe there is a way to organize the form response sheet to filter the data into their appropriate sheets.
I am out of my depth and could really use some help.
You can set up a linked Sheet to the Form and then an Apps Script function that gets the data and prints it into the Sheet.
First you have to create an Installable trigger: On form submit so every time the form is submitted the Sheet will be updated
Once you have your trigger set up, you have to write the function.
I would suggest you to create variables for each sheet you want your data in.
You can select the sheet by name like: sheet.getSheetByName("MachineX")
I recommend setting up the questions in an order that allows you to say:
From question 1 to 6 -> go to "MachineX"
From question 7 to 19 -> go to "MachineY"
Now you have to iterate over the answers and get the latest responses:
- If you just want the latest response to the form you could use something like:
for (var i = formResponses.length - 1; i < formResponses.length; i++)

Google Sheets Insert Row Form

I have a running parts order list that several people use. I am trying to have the top row be a form so the user enters Qty, Part #, and Notes and presses Enter. I want it to add a row to the top of the sheet below the headers and maintain the table structure so we can filter.
Instead of using the top row, go to Tools then create form. This will make it easier to input stuff. Also no one can muck up your sheet.
Also I would read what you can post here :) I like to be friendly so I thought I'd put an answer
You should read about Google Apps Script. GAS is the easiest way to read/write data in Google Spreadsheet/Docs/Forms.
So as far as I understand from your question, you need to insert a row in Google Spreadsheet below the header directly as soon as the forms.
Step 1: Open the spreadsheet using openById(id)
Step 2: Get the worksheet in which you want to save your Google Forms data using getSheetByName(name)
Step 3: Insert row before specified position using insertRowBefore(beforePosition)
So final code should look like this.
var spreadsheet = SpreadsheetApp.openById("1BZuYFCnN_g9vn5crxbPeYlhUKwH6N3u0uT8LCmm-neM");
var sheet = spreadsheet.getSheetByName("Nov-2017");
sheet.insertRowsBefore(2);
The code above will insert only one row below spreadsheet headers. There is an alternative -> insertRowsBefore(beforePosition, howMany) if you want to insert multiple rows at a specified position.
Try this and let me know if you find any difficulties. Hope this is what you're looking for.