0

I'm working on a simple google script for a spreadsheet that will go down a column in the sheet and update the column next to it based on information pulled from links in the original column.

The problem is that the same output is being output regardless of the input column. My code is here:

function idThatSucka() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var range = ss.getRange("F2:F20");
  for (var y = 1; y <= range.getHeight(); y++) {
    var logCell = ss.getRange("E"+y+":E"+y);
    var url = ss.getRange("F"+y+":F"+y).getValue();
    if (url){
      var response = UrlFetchApp.fetch(url);
      Logger.log(response.getContentText());
      var theLog = Logger.getLog();
      var start = theLog.split('</title>')[0];
      var output = start.split('Steam Community :: ')[1];
      logCell.setValue(output);
    }
  }
}

I suspect that "url" might not be updating, but nothing I've tried so far has fixed the problem.

  • Well have you tried logging it to the console? right after you declare the url variable write out console.log(url); – Rashid 'Lee' Ibrahim Oct 14 '17 at 01:43
  • I just tried that. No change in the output occurred. – Brice Darden Oct 14 '17 at 01:45
  • What did the console say? – Rashid 'Lee' Ibrahim Oct 14 '17 at 01:46
  • How would I go about accessing the console? – Brice Darden Oct 14 '17 at 01:48
  • I don't remember off the top of my head how to do it in the other browsers, but in chrome, you right click. Tap inspect. Then click on console. I found this in the spreadsheet documentation https://developers.google.com/apps-script/reference/base/logger – Rashid 'Lee' Ibrahim Oct 14 '17 at 01:49
  • I am using chrome. I cleared the console and then ran the script but the console remained blank. – Brice Darden Oct 14 '17 at 01:53
  • Check out this stackoverflow for more information on the google spreadsheet Logger function https://stackoverflow.com/questions/11539411/how-to-debug-google-apps-script-aka-where-does-logger-log-log-to Specifically this comment Logger.log('firstLog');MailApp.sendEmail({to:'yourEmailAddre‌​ssHere@someone.com',‌​subject: "subject here ^_^",body: Logger.getLog()}); – Rashid 'Lee' Ibrahim Oct 14 '17 at 01:57

1 Answers1

0

Try like this

function idThatSucka() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
 var range = ss.getRange("F2:F20");
for (var y = 1; y <= range.getHeight(); y++) {
 var url='';
 var logCell='';
   logCell = ss.getRange("E"+y+":E"+y);
   url = ss.getRange("F"+y+":F"+y).getValue();
  if (url){
  var response = UrlFetchApp.fetch(url);
  Logger.log(response.getContentText());
  var theLog = Logger.getLog();
  var start = theLog.split('</title>')[0];
  var output = start.split('Steam Community :: ')[1];
  logCell.setValue(output);
 }
}
}