Google Apps Script Form File Upload Response Return Id

What are Add-ons?

Add-ons are customized applications that integrate with Google Workspace productivity applications, such every bit the Grade Publisher add-on. Most Add-ons are built using Google Apps Script.

What goes into the making of an Improver?

Most Add-ons are congenital using Google Apps Script and various other languages. In this weblog, we will be using Google Apps Script and some HTML to build the carte for the Improver.

In 1 of the previous blogs, I showed you how to Limit Responses in Google Forms using Google Apps Script. In this blog, I am going to show you how to create an Add-on using the aforementioned Google Apps Script code that we had written.

If you oasis't read the blog, cheque out the link below.

https://form-publisher.com/web log/limit-responses-in-google-forms-using-google-apps-script/

If you prefer to sentry a video instead of reading, we've got you covered:

Footstep i: Sample Google Form

The form that I volition be using is a Simple Registration course. (If you lot prefer working with the Google Grade click here).

The form contains the following details:

  1. Proper noun of the Attendee
  2. Email Address of the Attendee
  3. Phone number of the Attendee


Step 2: Create the Bill of fare

Before we become to the main script, nosotros are offset going to create the Improver card where the user will input the maximum responses.

While yous are in the Form, launch the Apps Script Editor.

To practise that:

(ane) Click on 3 dots next to the Send button on the summit right.

(2) Next click on the Script Editor option.

This brings up the Script Editor equally shown beneath:

We have reached the Script Editor. Let's Code.

To create the Add-on carte we are going to utilise some HTML. To write HTML code, you have to open up a new HTML file, to do that follow these steps :

  1. Click on the plus push button, adjacent to Files.


ii. On clicking the plus push button, you will exist provided with two options: create a new Apps Script file or an HTML file.

three. Click on HTML and in a few seconds, an HTML file will go added to your Google Apps Script Project.

              <div class="sidebar">   <div form="block form-group">     <p><b> Limit Course Responses</b> </p>       <input type="number" id="max_responses" name="max_responses"   placeholder="Enter the Max Responses"/>       <push button class="blue" id="load_responses" onclick="openResponsesWindow()">Fix Limit</button>     </div>   </div>   <script>    office openResponsesWindow() {     const maxVal = document.getElementById("max_responses").value;     google.script.run.limit_responses(maxVal);     console.log("function invoked");   }  </script>            

This is the HTML code that will exist used to make the Add-on menu.

              <div class="sidebar"> <div class="cake class-group"> <p><b> Limit Form Responses</b> </p>            

Here we have created a div with the id sidebar. Since we are going to take values from the user, nosotros have to create a course. To do that, we have added the course-group that add some structure to forms. Side by side, we are adding some text to the card using <p>(represents a paragraph in HTML).

              <input type="number" id="max_responses" name="max_responses" placeholder="Enter the Max Responses"/>  <push class="bluish" id="load_responses" onclick="openResponsesWindow()">Prepare Limit</button>            

Here nosotros take used the input to enter the maximum responses in the Google Form. Here we have specified the input type as a number, side by side we have specified the id and name of the input, which we will exist using a bit later. Next, nosotros have specified some text in the placeholder that will come before the input box.

Here nosotros have created a new button with the ID load_responses. On clicking the button we accept to run the Google Apps Script code that limits responses in Google Forms. Using the Onclick command nosotros can assign the role that nosotros want to run by clicking the push button.

              <script>     function openResponsesWindow() {         const maxVal = certificate.getElementById("max_responses").value;         google.script.run.limit_responses(maxVal);         console.log("function invoked");     } </script>            

Nosotros are going to open the part that we passed in the Onclick command. Next, nosotros are going to get the maximum responses and store it in a variable using the Document.getElementById, by passing the input role id. Using the google.script.run we will run the limit_responses part past passing the maxim responses variable.

We have completed the code for the Add together-on carte.

Footstep 3: Google Apps Script Lawmaking

To switch back to writing Google Apps Script just click on code. gs file.

              function onOpen(){     FormApp.getUi().createAddonMenu().addItem('Open','show_sidebar').addToUi();  }  function show_sidebar() {     const html = HtmlService.createTemplateFromFile("google_forms").evaluate().setTitle("Grade Limitter Addition");        FormApp.getUi().showSidebar(html);   }  function onformsubmit(){     const limit_value = PropertiesService.getDocumentProperties().getProperty("limit"); console.log(limit_value);     const form = FormApp.getActiveForm();     const responses = form.getResponses();    //Logger.log("The maximum responses are : " + maximum_responses);   const len = responses.length;        Logger.log(len)    if (len == limit_value){      form.setAcceptingResponses(fake);   }  }  function limit_responses(maximum_responses){    PropertiesService.getDocumentProperties().setProperty("limit",maximum_responses);    const grade = FormApp.getActiveForm();   const responses = course.getResponses();   //Logger.log("The maximum responses are : " + maximum_responses);   const len = responses.length;   Logger.log(len)    if (len == maximum_responses){      grade.setAcceptingResponses(false);   } }            
              office onOpen(){     FormApp.getUi().createAddonMenu().addItem('Open','show_sidebar').addToUi(); }            

To open the Add-on in the Google Course, nosotros have to get the UI of the Google Form, using the FormApp.getUi(). Adjacent, we are going to create the Add-on menu using the .createAddonMenu() and pass in the sidebar id that we had previously created in the HTML part.

              office show_sidebar() {     const html = HtmlService.createTemplateFromFile("google_forms").evaluate().setTitle("Form Limiter Add-on");     FormApp.getUi().showSidebar(html); }            

Here we are going to create the Template from the HTML file that we just created. Side by side, we are going to set the Title for the Add-on.

              function onformsubmit(){     const limit_value = PropertiesService.getDocumentProperties().getProperty("limit");            

Nosotros have successfully created the template to write the lawmaking to accept the values from the user and store it in the variable.

Using the Properties service we are going to shop the value that the user enters in the Add-on. The getDocumentProperties() control stores the data entered past the user in the Add-on. Next, we are going to employ the getProperty command and store it in the limit_value variable.

                              const form = FormApp.getActiveForm();   const len = responses.length;    Logger.log(len)    if (len == limit_value){    course.setAcceptingResponses(false);    } }            

This part of the script has already been covered in the previous blog. If yous haven't read the blog, click here.

Our lawmaking for the Improver is complete.

Pace iv: Check the Output

Our code is complete. Select the correct office (OnOpen) as shown beneath and run the program.

To run across the Add-on, go back to your Google Form and click on the Add-on button.

On clicking the Limit Responses Add-on you will get the following options.

Click on Open, to showtime the Addition. On successful execution of the script, you will see that the Add-on volition appear on the right side of your Google Form.

Here I have set the limit to ii responses and clicked on the Set Limit push button.

Hither you can run into that on reaching two responses the Google Form has automatically closed.

Summary

We saw how you tin can build a unproblematic Google Form Add-on that limits responses using Google Apps Script and some HTML.

Promise you enjoyed the blog. Feel free to accomplish out if you accept whatsoever issues/feedback at aryanirani123@gmail.com.



nugentthentort.blogspot.com

Source: https://form-publisher.com/blog/build-a-simple-google-form-add-on-using-google-apps-script/

0 Response to "Google Apps Script Form File Upload Response Return Id"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel