I have two sheets in on spreadsheet.
The first sheet I get data from external API to see all upcoming classes which constantly updates via triggers.
id | class | start | finish | description 1 tig welding 7/6/2013 10:30 7/6/2013 12:30 class description 2 tig welding 7/8/2013 10:30 7/8/2013 12:30 class description 3 Serger Basics 7/8/2013 14:30 7/6/2013 16:30 class description
The second is a static classes list where I add a second column "category".
class | category tig welding metalworking Serger Basics textiles
I would like to check if the titles in both spreadsheets match, and if so add category to the first sheet, like:
id | title | start | finish | description | category
I then serve that spreadsheet as JSON to 3rd party web app. Sounds like a lot of work, but haven't came up with any other solution. Here is the work in progress code with a note where I am stuck.
function listClasses(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0]; //list of all upcoming classes
var sheet1 = ss.getSheets()[1]; //list of titles
var data = sheet.getDataRange().getValues(); // read all data in the sheet
var data1 = sheet1.getDataRange().getValues();
for(n=1;n<data1.length;++n){
var title1 = data1[n][0];
var category = data1[n][1];
// compare Check if title appears in column A of sheet 2.
if (ArrayLib.find(data1, 0, title1) != -1) {
// Yes it does, do something in sheet 0
for( var row = data.length -1; row >= 0; --row )
if (data[row][1] == title1){
var id = data[row][0];
var title = data[row][1];
var start = data[row][3];
var finish = data[row][4];
var description = data[row][5];
var category = data1[n][1];
// and here is where I got stuck!
data.appendRow([category]);
}
}
}
}