Release grade immediately after submission - how to do using Apps Script - google-apps-script

I am using the following lines of Apps Script to dynamically generate a Google Forms Quiz
form.setIsQuiz(true);
form.setTitle("New")
.setDescription('Test')
.setConfirmationMessage('Thanks for responding!')
.setAllowResponseEdits(false)
.setAcceptingResponses(true)
.setLimitOneResponsePerUser(true)
.setShuffleQuestions(true)
.setProgressBar(true)
.setCollectEmail(true)
This is creating a form and i am able to send out the quizzes to multiple people. But i also want to "Release Score >> Immediately After Submission". This is a feature in Google Quiz Form. But i am unable to find a method equivalent to the Google Forms feature of "Release Score >> Immediately After Submission".
I cannot do this manually for each form because i generate hundreds of forms distributed to different sets of people.

AFAIAA, there is no means to do this directly using a Google Apps Script method at this time.
A possible workaround is to create a minimal Google Form, make it a quiz, and configure it to 'Immediately after each submission'. Instead of creating the form within the script, merely duplicate this Form file (using your script) and proceed to build your quiz programmatically in the copy.
It is worth noting that this omission in Google Apps Script can result in a bug in the completed quiz. When a Form is created using a script and .setIsQuiz(true) method is used to to turn it into a quiz, the "Release marks" setting defaults to "Later, after manual review". In the Forms settings User Interface, this option includes the note "Turns on email collection" - This is so that when results are released manually, there is an email address to send the results to. When a Quiz is created using the steps above, email collection is not enabled. This means it is not possible to release the results manually. The workaround described above alleviates this issue.

Related

How to connect an html form submission on an external web app to a user's google sheet?

There are plenty of examples on how to use an apps script web app to connect HTML forms to google sheets. However all these refer to a scenario where the owner of the spreadsheet/form is the developer, such as this method. The owner/creator of the spreadsheet/form is not dynamic in these cases as far as I can see.
In my use case I want users to create their own HTML Forms based off data from a spreadsheet in their drive and receive responses in that sheet. So we are talking about multiple users creating their own spreadsheet in their own google account/drive instance and connecting that to my external web app to display the form to the users who have the link.
The flow is like this:
User1 creates Google SpreadSheet in their drive
User1 uses our add on to create the form/link
User1 sends the links out
Receiving Users go to the link which leads to my external web app to fill out the form and submit a response
User1 receives responses in another sheet in the same spreadsheet in their drive.
This is repeated for x amount of users.
I'm thinking this will be done through a sheet add on, but I'm not sure how to connect the add on to the external web app. In the link above it is done by creating an apps script web app, but I can't ask the user to do that/programmatically do it for them.
What options do I have?
There needs to be a url to send data to, with a process listening for said data that I can then run a function on.
Hopefully there is some api for this, maybe for drive?
P.S In case anyone is suggesting that I use google forms for this, google forms is great but it is limited in UI options and to a question and answer format. I'm looking to include search/filter functionality for possibly hundreds of list items with a quantity field. So it can't be done in forms.
This should be possible given the following constraints: 1. The form "owner" would need to pass the Sheet IDs of the source and destination to you and, 2. both of those Sheets would need to be publicly readable and writeable.
AppScript is great for manipulating Docs and Sheets you own, but in your case you'll want to use the core Sheets API instead.
Your application which handles responses is probably best implemented using one of the SDKs depending on which language you write it in.

One-time script authorization for templated spreadsheets

We built a purchase order system in Google Docs using Google App Script. The basic structure is a Google Web App, in which the user selects a few options, that app then clones Google Sheet templates to produce a Purchase Order (PO) document. The template includes a trigger to load an app script library we wrote, which is a set of custom menu options to control the PO workflow. Everything works well, except that every time a new PO is created (again, cloning from a template sheet), the users are required to re-authorize the app script. This adds several additional steps per person that are totally redundant. This is likely because the script is bound to the document, but not sure how to get around this since it creates custom menus and needs to be loaded on open.
Any way to have the user authorize the script once for all copies of the template?

How would I implement for loop using google script to edit a google form?

I am very new to scripting on Google form. In fact, I just recently fount out about it.
So what I'm trying to do is that I want to create a form that consists of duplicated pages in accordance to a number that is chosen by the user.
For instance, the form asks the user "How many people will be participating in this event?" If the user types in 5, the form will make 5 duplicates of a page, in which all of those pages will ask for the details of each participant.
So is there a way create duplicates of a page using a for loop?
First, you'll need to implement using installable form-submit trigger which runs when a user responds to a form.
For more information, check these two versions of the form-submit trigger:
Google Forms events
Google Sheets events
Then, when triggered, you may want to create new documents using the append methods in Class Body.
See this related SO posts for more insights and sample codes:
Duplicating a page of a document and replacing text on each page
Google app script copy document page

Google Apps Script - Always allow app to run

I wrote a script in GSheets we use at my work that uses custom menus. Because everyone is set to "Can view" on the template, they are forced to make a copy as to not affect the template.
The downside of that is each spreadsheet will require authorization to run every single time the form is sent in and the menus need to be used which makes the process more cumbersome. Is there a way I can provide authorization to run the code, whether it be through an onOpen trigger or some other means?
The code includes moving sheets into folders, extracting data to a central spreadsheet, and sending emails. The email does not need to come from the user, it can be sent as a no-reply/anonymous user if that helps.

Make a Google web app that's triggered from a Google Spreadsheet form?

I have a Google Apps script (written in a Google Spreadsheet) that creates a separate calendar and events for it with respect to a university course and the university calendar. The GUI is a Spreadsheet form, which triggers the execution of my script. The script gets its input from the spreadsheet form entry.
The trouble I have is that I can't easily deploy my solution to other users. Yes, they can make a copy of my sheet/form/scripts, so that they can run it on their account. Several problems, however, result from this approach:
triggers don't get copied - this is because authorization to access local info (calendars, contacts, etc.) must be given by the users before a trigger is enabled. So users have to re-connect the form submission trigger to the Apps Script for it to work (this is not user friendly).
if I change the code of my apps script, the users are using a copy and won't see the changes.
The solution seems to be Google Web Apps, but from what I've read, I can't re-use the form-based GUI of my approach. Or can I?
Google Spreadsheet Forms have the advantage that they are very easy to create, and you can already specify what fields are mandatory, etc. I don't want to have to re-write all of this in a complicated GUI front-end to my Google Apps Script (Edit: even the GUI builder tool seems way more complicated than a Spreadsheet Form), yet I want other users to be able to create the calendars and events in their own Google accounts. Is there a way to keep my form, but have it hooked to a Web App version of my code?
Try adding the form on a google sites (intranet). This way, any user having access, will be able to use the form as it is. All logic you created will remain the same.
Creating a script however will allow the user to execute the script "under their login", thus enabling access to calendars, contacts......