Snippets

Frederick Vallaeys boEpo: Untitled snippet

Created by Frederick Vallaeys
var GOOGLE_SPREADSHEET = "https://docs.google.com/spreadsheets/d/1bwlTv7pr63Z0HVVTE6iVh1rli5ogLuA_hWoIm8Pnbn0/edit";
var TAB_WITH_VARS = "My Variables";

function main() {
  var accountSelector = MccApp.accounts()
    .withLimit(50);

  accountSelector.executeInParallel("processClientAccount", null);
  
}

function processClientAccount() {
  
  SETTINGS = new Object();
  SETTINGS.taskSheet = SpreadsheetApp.openByUrl(GOOGLE_SPREADSHEET).getSheetByName(TAB_WITH_VARS);
  
  var rows = SETTINGS.taskSheet.getDataRange();
  var numRows = rows.getNumRows();
  var numCols = rows.getNumColumns();
  var values = rows.getValues();
  
  // Read Header Rows
  var headerNames = new Array();
  var row = values[0];
  for(var i = 0; i < numCols; i++) {
    var value = "" + row[i];
    headerNames[i] = value;
  } 
  
  // Read Data Rows With Settings
  for(var i = 1; i<numRows; i++) {
    SETTINGS.taskMasterRow = i+1;
    var row = values[i];
    for(var j = 0; j < headerNames.length; j++) {
      var headerName = headerNames[j];
      var value = row[j];
      SETTINGS[headerName] = value;
      //Logger.log(value);
    }
    
    
    // If the account is right
    if(AdWordsApp.currentAccount().getCustomerId().replace(/-/g,"") == SETTINGS.accountId) {
      Logger.log(SETTINGS.variable1 + " " + SETTINGS.variable2);
    }
  }   
}

Comments (0)