Use button in Google Sheets to open the pre-filled Google Form from dynamic hyperlink - google-apps-script

Issue:
I have a Google Form, let's call it "Stock". The form simply records new entries of stock into the Google Sheet "Stock Form Responses". In this sheet, there is a field called Stock Number which has to be unique. In order to cut out human error in the process of assigning a new stock number to the rows of data added through the form, I have created a very simple formula in a cell:
=max('Stock Form Responses'!B:B)+1
This does exactly what I need it to do, and tells me the latest stock number, and adds one to it, ready for the next addition via the form. I then use this code in another cell (G9 of the sheet called "Control"), to pass that number to the prefilled form link for my form, like this:
=concatenate("https://docs.google.com/forms/MYFORMLINK/viewform?usp=pp_url&entry.465281926=",D10)
This is where D10 from the Control sheet stores the previous calculation of what the next stock number should be.
All of this works great so far, and everything works fine.
Problem:
Google Sheets has this really annoying feature where you can't just click a link in the sheet, you have to hover over it and then click the attached link. It's frustrating, and I'm trying to simplify and clean up steps. I simply want to pass the URL stored in G9 to an action attached to a button, let's call it AddStock. How do I do this?
I've been trawling the internet for hours trying to work it out, and can't seem to figure it out myself (admittedly I have very limited coding understanding, but people keep talking about popup blockers, etc).

Related

Google Sheets: Why can't I insert a link (to anything) in a cell containing a formula

In any Google Sheet, select a cell containing a formula, for example, =SUM(1,1). You'll see that both the Insert->Link menu
and the toolbar button for Insert Link (Ctrl + K) are disabled.
Why is that?
PS:
I've spent considerable time on Google, but I haven't found this issue mentioned anywhere.
This problem occurs irrespective of whether the formula has been manually typed in the cell or been populated through Apps Script.
This is intended behaviour
If you press Ctrl+K when a cell with a formula is highlighted you get the following message:
Not sure if this applies to you, but I solved my problem after coming here. I realized that where I was trying to change the links was actually an "importrange" of another file. So I have a daily sales ticker that feeds out to our salespeople, but I don't want them to "see" my live file and accidentally make changes. So I use "importrange" to show just one page of my big file to the salespeople and if they accidentally make a change, it doesn't affect my original formulas. I was trying to update the links on the "shared version". Once I went to my original file, I could update the links as expected. It was ODD though that I was able to delete the link on the shared page. Just couldn't edit it or create a new link there.

FILE_UPLOAD item type in Google Apps Script (GAS) for Form Submission

I've seen FILE_UPLOAD item type in google forms regarding this topic.
My problem is related, but somewhat different--perhaps someone can recommend a workaround?
Situation: Using Google Forms as content submission and editing tool for certain kinds of "documents," with a specific form for each document.
Objective: copy an original form submission to create through GAS a NEW form submission with the same item responses.
This is based on a response in the original form submission indicating that a variant also needs to be created based on the original content.
Example: Another form entry is needed where the original content is translated to a different language (with first draft using google translate and then revised by native speaker using the Google form). In other cases, only portions of a long original submission need to be revised to create the variant document, where the revisions are made to the duplicated submission in the Google form.
Things are fine except where the form(s) have image upload options and I need to copy the FILE_UPLOAD content of the original form response back into the new scripted form submission. But it appears required to specify the item type (e.g., .asTextItem(), .asCheckBoxItem(), etc.). But there is no .asFileUploadItem() option (I tried using it), and therefore an error is thrown, preventing the copy of FILE_UPLOAD content into the corresponding question item of the form. I've tried using .asTextItem(), since the G-Drive address is just a text string (at least in the paired Google Sheet), but the Form won't accept that. It seems (at least in our case) that the original file location would work for all variant duplicates that retain the same image, so copying the content (the G-Drive location of the image) should be fine, if GAS allowed me to do that.
Is there any workaround provided by Google, now that it is a year later than the previous post I found (above)? Has anyone come up with a workable solution that might work for my case?
Thanks so much for any help!

Grab current selection from a google form section

I have a google calendar that lists multiple free classes that are available each month. Currently the way people sign up is that they click on a link to a google doc and enter their names, but a blank work doc with names isn't very professional. Instead I'm created a google form that will send the responses to an excel spreadsheet, but need some help.
Currently the form first question asks "what date is the class you'd like to addend?" - Is there any way I can get the users response to that first question without having them submit the form?
Essentially I'd like for them to enter the date and use the getEventsForDay(date) function to create the second question dynamically populated with the calsses for the date they selected. Then have them choose the class with radio buttons. Is there any way to do this or would I have to have them select a date and then from that submit spawn a new on the fly form that then would list the classes for the date they selected?
For what I know you can't do that in a single form. You will need to do it with 2 forms. You can prefill the other form with some informations of the first form to make the bond.
But the best solution is: not to use the Google Forms and build your own form in apps script. Here an example and the code here.

Google form with a filter field

I'm trying to create a google form with a field which takes the values as a list from spreadsheet. Right now i'm using formRanger scrip but my list is to long, 200 entries, how can i make it similar to android contact search. That it will filter the entries based on keystroke.
So it seems that nothing has changed in the last 8 years and the best solution to date seems to:
put the long list as a single question on separate section
advice users to use Ctrl+F to find the needed option.
This has advantage over drop-down that it's much easier to scroll the whole page than dropdown which user can accidentally close and will need to open and search again.
It sounds like you are looking for an "Autocomplete" entry for your form.
As the user types an entry into the form field, a dropdown list appears showing matching entries lifted from a Google spreadsheet column.
The following solution using HtmlService works great for lists having over 200 entries.
I've tried it!
"Populate jQuery autocomplete list using value array from Google Spreadsheet"

Linking one cell to another in a spreadsheet

I have a dynamically generated spreadsheet. I would like to be able to allow the viewer to go to a different sheet/cell when a cell is clicked on. I'm having trouble figuring out a good way to do this.
Going to the new cell is fairly easy: Spreadhseet.setActiveSheet()/Spreadsheet.setActiveRange() work fine. My thought was to encode the link destination in the contents of the source cell, and then write a script to "follow" the link.
I tried using images or drawings. But there were two problems with this: while images can be inserted programmatically, I did not see a way to programmatically associate a script with them. And the called script does not have an associated event tied to it, so there is no way to see what cell the user clicked (clicking an image does not set the active cell).
I thought about using onEdit(). This almost works, but onEdit is only triggered on changes (not selection) so the user actually has to modify the cell in order to "link". When testing I tended to zap the contents of the cell by accident with onEdit.
I tried making a menu item, and in the menu's script get the active cell's contents to determine where to go to. This worked but was a bit more difficult for the user than I was hoping for.
I was hoping someone would have a creative solution to this problem.
Thanks!
From what you are describing the drawing or image insertion should work since it has exactly the same functionality as the menu item. You can assign a script to it just like in a menu.