-
Notifications
You must be signed in to change notification settings - Fork 15
/
createKeyFromEmail.gs
21 lines (20 loc) · 904 Bytes
/
createKeyFromEmail.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function createKey(email) {
var randNumber = Math.floor(Math.random() * (10000000 - 1000000 + 1)) + 1000000;
var digitalSignature = email.substring(0,email.indexOf("@"))+ "-"
+ email.substring(email.indexOf("@")+1, email.length).substring(0,email.substring(email.indexOf("@")+1, email.length).indexOf("."))
+ "-" + randNumber;
return(digitalSignature);
}
function onEdit(e){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("NAME-OF-SHEET");
var lastRow = sheet.getLastRow();
for (i = 1; i <= lastRow; i++) {
var digitalSignature = sheet.getRange(i,12);
Logger.log(digitalSignature.getValue());
var emailForDS = sheet.getRange(i,8);
Logger.log(emailForDS.getValue());
if ((digitalSignature.getValue()==0) && !(emailForDS.getValue()==0)){
digitalSignature.setValue(createKey(sheet.getRange(i,8).getValue()));
}
}
}