JSFiddle - React, Tailwind, and code Playground

by tsdexter

JavaScript

/**
 * Adds a custom menu to the active spreadsheet, containing a single menu item
 * for invoking the readRows() function specified above.
 * The onOpen() function, when defined, is automatically invoked whenever the
 * spreadsheet is opened.
 * For more information on using the Spreadsheet API, see
 * https://developers.google.com/apps-script/service_spreadsheet
 */
function onOpen() { 
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var entries = [{
    name : "Add Dealers by FSA",
    functionName : "addDealers"
  }];
  spreadsheet.addMenu("Weed Man Functions", entries);
};

function addDealers(aUrl,sheetname) {
  var ui = SpreadsheetApp.getUi();
  ui.alert("Begin processing data? (once processing begins do not edit the worksheet until you see the \"Done!\" message.)");
  var sheetname = "temp";
  var aUrl = "http://wearecoop.ca/dev/weedman/fsas.json";
  var response = UrlFetchApp.fetch(aUrl); // get feed
  var dataAll = JSON.parse(response.getContentText());
  var s = SpreadsheetApp.getActiveSheet();
  var data = s.getRange("E2:F").getValues();
  
  s.insertColumnAfter(9);
  for (row = 0, len = data.length; row < len; row++) {
    //ui.alert(data[row][1]);
    var drows = [];
    if(data[row][1] == "Tell Us About Yourself") {
      var fsa = dataAll[data[row][0].substring(0,3).toUpperCase()];
      if (typeof fsa === "undefined"){
        s.getRange("J2:J").getCell(row + 1, 1).setValue("unknown");
      } else {
        s.getRange("J2:J").getCell(row + 1, 1).setValue(fsa[0].subdomain);
      }
    } else {
      drows.push(row);
    }
  }
  s.sort(10);
  ui.alert("Done!");
}