Reputation: 11
So I have 2 sheets in a Google spreadsheet document.
SHEET 1 has one column with following data:
ID
1
2
3
4
5
6
7
8
9
..
And then SHEET 2 has 2 columns with following data:
ID EMAIL
1 [email protected]
2 [email protected]
7 [email protected]
...etc
I need to run a script on "Form Submit" which does the following:
Can someone please help me with this? Both these sheets are in the same google document.
Thank you!
Shashi
Upvotes: 1
Views: 539
Reputation: 27282
Not sure what you want to achieve here. If this 'lookup' is part of a wider onFormSubmit, you can create a fuction that is called when needed, passing in the ID and the spreadsheet.
function yourMainFunction() {
var ss =
...
var id =
var email = lookupEmail(id, ss)
....
...
}
function lookupEmail(id, ss) {
var lookupSheet = ss.getSheets()[1]; //second sheet
var data = lookupSheet.getDataRange()
.getValues()
var email;
for (var i = 0, len = data.length; i < len; i++) {
if (data[i][0] == id) { //id's are in the first column
email = data[i][1] //email is in the second column
} else {
email = null; //if not found return null
}
}
return email;
}
Upvotes: 0