Created
November 3, 2017 22:28
-
-
Save ashwoods/a9efdbac8bf8006916c1049ab89e222a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function slugify_(text){ | |
return text.toString().toLowerCase() | |
.replace(/\s+/g, '-') // Replace spaces with - | |
.replace(/[^\w\-]+/g, '') // Remove all non-word chars | |
.replace(/\-\-+/g, '-') // Replace multiple - with single - | |
.replace(/^-+/, '') // Trim - from start of text | |
.replace(/-+$/, ''); // Trim - from end of text | |
} | |
function doOnFormSumbit(e) { | |
Logger.log("Starting OnFormSubmit"); | |
var doc = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = doc.getSheetByName("Overview"); | |
var row = sheet.getLastRow(); | |
// create slug - used for sheet names and slack rooms | |
var slug = slugify_(sheet.getRange(row, 3).getValue()); | |
var slug_field = sheet.getRange(row,4).setValue(slug); | |
// see if new sheet | |
var sheetToWrite = doc.getSheetByName(slug) || null; | |
// if new sheet copy vorlage | |
if (sheetToWrite == null){ | |
var template = doc.getSheetByName("Vorlage"); | |
var new_sheet = template.copyTo(doc); | |
new_sheet.setName(slug); | |
new_sheet.setTabColor(null); | |
} | |
} | |
function onOpen(e){ | |
Browser.msgBox("Hi!"); | |
} | |
function onInstall(){ | |
if (ScriptApp.getScriptTriggers().length === 0) { | |
ScriptApp.newTrigger("doOnFormSumbit") | |
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet()) | |
.onFormSubmit() | |
.create(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment