# Google Forms Scripts

## Script editor

![](https://3264659121-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh5c6I1CKUNWFu57uxg%2F-LlHSAtH61_2OWwcydaH%2F-LlH_bUWX5f17xXTGPqf%2Fimage.png?alt=media\&token=3908e7f0-ad93-4c1f-bd9a-adab1480d991)

## Challenge #1

Let's imagine you're running a new program during a sort of free period at school. You need to track students that have the choice of multiple locations. You don't have time to get your school's attendance system in line with this new, flexible program. Instead, you'd like to share a Google Sheet with all your students and have teachers quickly note student locations using that form.

### What our script will do

All we've been asked to do is automatically create a new column for every weekday. Column A will be the student's name. Column B needs to be *today*.&#x20;

Google Forms script editor uses JavaScript. [Don't be afraid to study up a bit.](https://www.codecademy.com/learn/introduction-to-javascript)

{% hint style="info" %}
None of this should be memorized. Use the patient power of GoogleFu to work the problem.
{% endhint %}

### Solution

```javascript
function dailyColumn() {
  // create a variable that accesses all tabs of my spreadsheet
  var ss = SpreadsheetApp.getActiveSheet();
  
  // create a variable that contains the first sheet
  var sheet = ss.getSheets()[0];
  
  // insert a new column (not zero-indexed like the line above)
  sheet.insertColumnBefore(2); 
  
  // add the date to the column
  var date = Utilities.formatDate(new Date(), "GMT-4", "dd/MM/yyyy");
  sheet.getRange('B2').setValue(date);

}
  
```

### Triggers

Now that we have our solution, we need to have it auto-run every day. For that we'll need to wade into Google's G Suite Developer Hub.&#x20;

![](https://3264659121-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh5c6I1CKUNWFu57uxg%2F-LlHSAtH61_2OWwcydaH%2F-LlHqyFvobBJTCQp9Ccb%2Fimage.png?alt=media\&token=c8d7e40c-adb8-4cb5-95a7-79c52f5b5838)

![](https://3264659121-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lh5c6I1CKUNWFu57uxg%2F-LlHSAtH61_2OWwcydaH%2F-LlHqowM0M3nxBqGKmC9%2Fimage.png?alt=media\&token=dd76da92-450a-49ce-b7b6-0ed5e1afad05)
