getRange of null error on code that previously worked - arrays

I searched the other instances of people reporting a "getRange" of null error, but none of them solved my issue. I had a form built in Google Sheets, and the code worked perfectly this morning until I made an inadvertent edit, tried to undo the change, but nonetheless I must have done something because the script stopped working.
The script is meant to:
Allow a user to create a record by inputing information using code 1000 on the Form sheet, and to save such information to the Data sheet
Display a record's information from the Data sheet on the Form sheet when the user enters a code greater than 1000 (a record locator ID)
Permit the user to update and save information for the record displayed
Reset the form to blank when either the new record is created, or the existing record has been updated.
It worked perfectly this morning, then kaput. I've been trying to debug unsuccessfully for hours, and here are error messages by function:
submitData
TypeError: Cannot read property 'getRange' of null (line 98, file
"Code")
getMember
Exception: Range not found (line 249, file "Code")
onEdit
TypeError: Cannot read property 'getActiveCell' of null (line 378,
file "Code")
I've been through every line of code, and I am stuck. I humbly request another pair of eyes to help me fix it. Below is the code, and here is a link to a copy of the form and data table I created with a sample row of data. Please ignore the data validation errors since I deleted proprietary information to create this copy, and please let me know if you have any questions. Thank you.
'''
//array for setValue on Data Centre and getValue by column from database
var cellId = ["J3","A"];
var cellPhoto = ["J32","B"];
//Location
var cellStreetAddress = ["D7","C"];
var cellCity = ["D8","D"];
var cellState = ["D9","E"];
var cellZip = ["D10","F"];
var cellCounty = ["D11","G"];
//Program data
var cellfiftyfive = ["H7","H"];
var cellIL = ["H8","I"];
var cellAL = ["H9","J"];
var cellMC = ["H10","K"];
var cellBeds = ["H12","L"];
//Property Summary
var cellPhase = ["K7","M"];
var cellLand = ["K8","N"];
var cellBuildable = ["K9","O"];
var cellPrice = ["K10","P"];
var cellGrade = ["K11","Q"];
var cellSource = ["K12","R"];
var cellClassification = ["K13","S"];
//Description
var cellSiteDescription = ["D16","T"];
var cellProjDescription = ["D21","U"];
//Site Information
var cellSiteVisit = ["L16","V"];
var cellTeamsLink = ["K17","W"];
var cellGoogleMap = ["K18","X"];
//Zoning
var cellZoningClass = ["K21","Y"];
var cellZoningDesc = ["K22","Z"];
var cellEntitlements = ["K23","AA"];
//Construction
var cellParkingType = ["K26","AB"];
var cellConstType = ["K27","AC"];
var cellUnitSizeRange = ["K28","AD"];
var cellTotalSqFt = ["K29","AE"];
//Financial
var cellTotalCost = ["D32","AF"];
var cellTotalCostDoor = ["D33","AG"];
var cellTotalCostSF = ["D34","AH"];
var cellTotalDebt = ["D35","AI"];
var cellTotalEquity = ["D36","AJ"];
var cellFDGEquity = ["D37","AK"];
var cellCapitalStructure = ["D38","AL"];
//EARLY
var cellDateProcessed = ["H42","AM"];
var cellMarketStudyLink = ["H43","AN"];
//Site Photo
var cellPhotoLibrary = ["K43","AO"];
//Stakeholders
var cellCoDev = ["D46","AP"];
var cellFeeDev = ["D47","AQ"];
var cellOperator = ["D48","AR"];
var cellPartner = ["D49","AS"];
var cellArchitect = ["D50","AT"];
var cellEngineer = ["D51","AU"];
var cellContractor = ["D52","AV"];
var cellBroker = ["D53","AW"];
//Schedule
var cellRezoning = ["H46","AX"];
var cellSitePlan = ["H48","AY"];
var cellPlanPermit = ["H49","AZ"];
var cellClosing = ["H50","BA"];
var cellExtensions = ["H51","BB"];
var cellTimeToClose = ["H52","BC"];
var cellEstConstStart = ["H54","BD"];
var cellEstConstLength = ["H55","BE"];
var cellEstConstFinish = ["H56","BF"];
//Additional Notes
var cellNotes = ["J46","BG"];
var cellDropped = ["J55","BH"];
//Date Stamps
var cellInputDate = ["L3","BI"];//var cellInputDate = ["D23","K"];
var cellUpdateDate = ["L4","BJ"];//var cellUpdateDate = ["H23","L"];
function submitData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("Form");
var datasheet = ss.getSheetByName("Data");
var lastrow = datasheet.getLastRow();
var myId = formSS.getRange(cellId[0]).getValue();
var maxId = findMaxId(datasheet.getRange("A2:" + "A" + lastrow).getValues());
var nextId = increaseId(maxId);
var lastRowId = datasheet.getRange(lastrow,1,1,1).getValue();
var nextId = increaseId(lastRowId);
var myId = formSS.getRange(cellId[0]).getValue();
var now = new Date();
//Location
var my_StreetAddress = formSS.getRange(cellStreetAddress[0]).getValue();
var my_City = formSS.getRange(cellCity[0]).getValue();
var my_State = formSS.getRange(cellState[0]).getValue();
var my_Zip = formSS.getRange(cellZip[0]).getValue();
var my_County = formSS.getRange(cellCounty[0]).getValue();
//Program
var my_fiftyfive = formSS.getRange(cellfiftyfive[0]).getValue();
var my_IL = formSS.getRange(cellIL[0]).getValue();
var my_AL = formSS.getRange(cellAL[0]).getValue();
var my_MC = formSS.getRange(cellMC[0]).getValue();
var my_Beds = formSS.getRange(cellBeds[0]).getValue();
//Property Summary
var my_Phase = formSS.getRange(cellPhase[0]).getValue();
var my_Land = formSS.getRange(cellLand[0]).getValue();
var my_Buildable = formSS.getRange(cellBuildable[0]).getValue();
var my_Price = formSS.getRange(cellPrice[0]).getValue();
var my_Grade = formSS.getRange(cellGrade[0]).getValue();
var my_Source = formSS.getRange(cellSource[0]).getValue();
var my_Classification = formSS.getRange(cellClassification[0]).getValue();
//Description
var my_SiteDescription = formSS.getRange(cellSiteDescription[0]).getValue();
var my_ProjDescription = formSS.getRange(cellProjDescription[0]).getValue();
//Site Information
var my_SiteVisit = formSS.getRange(cellSiteVisit[0]).getValue();
var my_TeamsLink = formSS.getRange(cellTeamsLink[0]).getValue();
var my_GoogleMap = formSS.getRange(cellGoogleMap[0]).getValue();
//Zoning
var my_ZoningClass = formSS.getRange(cellZoningClass[0]).getValue();
var my_ZoningDesc = formSS.getRange(cellZoningDesc[0]).getValue();
var my_Entitlements = formSS.getRange(cellEntitlements[0]).getValue();
//Construction
var my_ParkingType = formSS.getRange(cellParkingType[0]).getValue();
var my_ConstType = formSS.getRange(cellConstType[0]).getValue();
var my_UnitSizeRange = formSS.getRange(cellUnitSizeRange[0]).getValue();
var my_TotalSqFt = formSS.getRange(cellTotalSqFt[0]).getValue();
//Financial
var my_TotalCost = formSS.getRange(cellTotalCost[0]).getValue();
var my_TotalCostDoor = formSS.getRange(cellTotalCostDoor[0]).getValue();
var my_TotalCostSF = formSS.getRange(cellTotalCostSF[0]).getValue();
var my_TotalDebt = formSS.getRange(cellTotalDebt[0]).getValue();
var my_TotalEquity = formSS.getRange(cellTotalEquity[0]).getValue();
var my_FDGEquity = formSS.getRange(cellTotalEquity[0]).getValue();
var my_CapitalStructure = formSS.getRange(cellCapitalStructure[0]).getValue();
//EARLY
var my_DateProcessed = formSS.getRange(cellDateProcessed[0]).getValue()
var my_MarketStudyLink = formSS.getRange(cellMarketStudyLink[0]).getValue()
//Site Photo
var my_Photo = formSS.getRange(cellPhoto[0]).getValue();
var my_PhotoLibrary = formSS.getRange(cellPhotoLibrary[0]).getValue();
//Stakeholders
var my_CoDev = formSS.getRange(cellCoDev[0]).getValue();
var my_FeeDev = formSS.getRange(cellFeeDev[0]).getValue();
var my_Operator = formSS.getRange(cellOperator[0]).getValue();
var my_Partner = formSS.getRange(cellPartner[0]).getValue();
var my_Architect = formSS.getRange(cellArchitect[0]).getValue();
var my_Engineer = formSS.getRange(cellEngineer[0]).getValue();
var my_Contractor = formSS.getRange(cellContractor[0]).getValue();
var my_Broker = formSS.getRange(cellBroker[0]).getValue();
//Schedule
var my_Rezoning = formSS.getRange(cellRezoning[0]).getValue();
var my_SitePlan = formSS.getRange(cellSitePlan[0]).getValue();
var my_PlanPermit = formSS.getRange(cellPlanPermit[0]).getValue();
var my_Closing = formSS.getRange(cellClosing[0]).getValue();
var my_Extensions = formSS.getRange(cellExtensions[0]).getValue();
var my_TimeToClose = formSS.getRange(cellTimeToClose[0]).getValue();
var my_EstConstStart = formSS.getRange(cellEstConstStart[0]).getValue();
var my_EstConstLength = formSS.getRange(cellEstConstLength[0]).getValue();
var my_EstConstFinish = formSS.getRange(cellEstConstFinish[0]).getValue();
//Additional Notes
var my_Notes = formSS.getRange(cellNotes[0]).getValue();
var my_Dropped = formSS.getRange(cellDropped[0]).getValue();
if (myId == 1000) { //input mode
var values = [
nextId,'',my_StreetAddress,my_City,my_State,my_Zip,my_County,my_fiftyfive,my_IL,my_AL,my_MC,my_Beds,my_Phase,my_Land,my_Buildable,my_Price,my_Grade,
my_Source,my_Classification,my_SiteDescription,my_ProjDescription,my_SiteVisit,my_TeamsLink,my_GoogleMap,my_ZoningClass,my_ZoningDesc,my_Entitlements,
my_ParkingType,my_ConstType,my_UnitSizeRange,my_TotalSqFt,my_TotalCost,my_TotalCostDoor,my_TotalCostSF,my_TotalDebt,my_TotalEquity,my_FDGEquity,my_CapitalStructure,
my_DateProcessed,my_MarketStudyLink,my_PhotoLibrary,my_CoDev,my_FeeDev,my_Operator,my_Partner,my_Architect,my_Engineer,
my_Contractor,my_Broker,my_Rezoning,my_SitePlan,my_PlanPermit,my_Closing,my_Extensions,my_TimeToClose,
my_EstConstStart,my_EstConstLength,my_EstConstFinish,my_Notes,my_Dropped,now
];
datasheet.getRange(datasheet.getLastRow()+1, 1, 1, 61).setValues(values);
clear_screen();
} else { //update mode
var rowIndex = findInRow(myId);
var rangesToSetValues = [cellStreetAddress[1], cellCity[1], cellState[1], cellZip[1], cellCounty[1], cellfiftyfive[1], cellIL[1],
cellAL[1], cellMC[1], cellBeds[1], cellPhase[1], cellLand[1], cellBuildable[1],
cellPrice[1], cellGrade[1], cellSource[1], cellClassification[1], cellSiteDescription[1], cellProjDescription[1],
cellSiteVisit[1], cellTeamsLink[1], cellGoogleMap[1], cellZoningClass[1], cellZoningDesc[1], cellEntitlements[1],
cellParkingType[1], cellConstType[1], cellUnitSizeRange[1], cellTotalSqFt[1],cellTotalCost[1], cellTotalCostDoor[1], cellTotalCostSF[1],
cellTotalDebt[1], cellTotalEquity[1], cellFDGEquity[1], cellCapitalStructure[1], cellDateProcessed[1], cellMarketStudyLink[1], cellPhotoLibrary[1],
cellCoDev[1], cellFeeDev[1], cellOperator[1], cellPartner[1], cellArchitect[1], cellEngineer[1],
cellContractor[1], cellBroker[1], cellRezoning[1], cellSitePlan[1], cellPlanPermit[1], cellClosing[1],
cellExtensions[1], cellTimeToClose[1], cellEstConstStart[1], cellEstConstLength[1], cellEstConstFinish[1], cellNotes[1],cellDropped[1]];
var values = [
my_StreetAddress,my_City,my_State,my_Zip,my_County,my_fiftyfive,my_IL,my_AL,my_MC,my_Beds,my_Phase,my_Land,my_Buildable,my_Price,my_Grade,
my_Source,my_Classification,my_SiteDescription,my_ProjDescription,my_SiteVisit,my_TeamsLink,my_GoogleMap,my_ZoningClass,my_ZoningDesc,my_Entitlements,
my_ParkingType,my_ConstType,my_UnitSizeRange,my_TotalSqFt,my_TotalCost,my_TotalCostDoor,my_TotalCostSF,my_TotalDebt,my_TotalEquity,my_FDGEquity,my_CapitalStructure,
my_DateProcessed,my_MarketStudyLink,my_PhotoLibrary,my_CoDev,my_FeeDev,my_Operator,my_Partner,my_Architect,my_Engineer,
my_Contractor,my_Broker,my_Rezoning,my_SitePlan,my_PlanPermit,my_Closing,my_Extensions,my_TimeToClose,my_EstConstStart,my_EstConstLength,
my_EstConstFinish,my_Notes,my_Dropped
];
for (var i=0; i<rangesToSetValues.length; i++) {
datasheet.getRange(rangesToSetValues[i]+rowIndex).setValue(values[i]);
}
//set lastupdateDate value
datasheet.getRange(cellUpdateDate[1]+rowIndex).setValue(now);
getMember(myId);
}
}
function getMember(id) {
var sheetData = SpreadsheetApp.getActive().getSheetByName('Form');
var rangesToSetValues = [cellStreetAddress[0], cellCity[0], cellState[0], cellZip[0], cellCounty[0], cellfiftyfive[0], cellIL[0],
cellAL[0], cellMC[0], cellBeds[0], cellPhase[0], cellLand[0], cellBuildable[0],
cellPrice[0], cellGrade[0], cellSource[0], cellClassification[0], cellSiteDescription[0], cellProjDescription[0],
cellSiteVisit[0], cellTeamsLink[0], cellGoogleMap[0], cellZoningClass[0], cellZoningDesc[0], cellEntitlements[0],
cellParkingType[0], cellConstType[0], cellUnitSizeRange[0], cellTotalSqFt[0], cellTotalCost[0], cellTotalCostDoor[0], cellTotalCostSF[0],
cellTotalDebt[0], cellTotalEquity[0], cellFDGEquity[0], cellCapitalStructure[0], cellDateProcessed[0], cellMarketStudyLink[0], cellPhotoLibrary[0],
cellCoDev[0], cellFeeDev[0], cellOperator[0], cellPartner[0], cellArchitect[0], cellEngineer[0],
cellContractor[0], cellBroker[0], cellRezoning[0], cellSitePlan[0], cellPlanPermit[0], cellClosing[0],
cellExtensions[0], cellTimeToClose[0], cellEstConstStart[0], cellEstConstLength[0], cellEstConstFinish[0], cellNotes[0], cellDropped[0],
cellInputDate[0], cellUpdateDate[0]];
var rowIndex = findInRow(id);
var sheetDatabase = SpreadsheetApp.getActive().getSheetByName('Data');
var values = [
//Location
sheetDatabase.getRange(cellStreetAddress[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellCity[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellState[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellZip[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellCounty[1]+rowIndex).getValue(),
//Program data
sheetDatabase.getRange(cellfiftyfive[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellIL[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellAL[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellMC[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellBeds[1]+rowIndex).getValue(),
//Property Summary
sheetDatabase.getRange(cellPhase[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellLand[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellBuildable[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellPrice[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellGrade[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellSource[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellClassification[1]+rowIndex).getValue(),
//Description
sheetDatabase.getRange(cellSiteDescription[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellProjDescription[1]+rowIndex).getValue(),
//Site Information
sheetDatabase.getRange(cellSiteVisit[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellTeamsLink[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellGoogleMap[1]+rowIndex).getValue(),
//Zoning
sheetDatabase.getRange(cellZoningClass[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellZoningDesc[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellEntitlements[1]+rowIndex).getValue(),
//Construction
sheetDatabase.getRange(cellParkingType[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellConstType[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellUnitSizeRange[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellTotalSqFt[1]+rowIndex).getValue(),
//Financial
sheetDatabase.getRange(cellTotalCost[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellTotalCostDoor[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellTotalCostSF[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellTotalDebt[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellTotalEquity[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellFDGEquity[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellCapitalStructure[1]+rowIndex).getValue(),
//EARLY
sheetDatabase.getRange(cellDateProcessed[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellMarketStudyLink[1]+rowIndex).getValue(),
//Site Photo
//sheetDatabase.getRange(cellPhoto[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellPhotoLibrary[1]+rowIndex).getValue(),
//Stakeholders
sheetDatabase.getRange(cellCoDev[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellFeeDev[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellOperator[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellPartner[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellArchitect[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellEngineer[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellContractor[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellBroker[1]+rowIndex).getValue(),
//Schedule
sheetDatabase.getRange(cellRezoning[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellSitePlan[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellPlanPermit[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellClosing[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellExtensions[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellTimeToClose[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellEstConstStart[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellEstConstLength[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellEstConstFinish[1]+rowIndex).getValue(),
//Additional Notes
sheetDatabase.getRange(cellNotes[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellDropped[1]+rowIndex).getValue(),
//Data Stamps
sheetDatabase.getRange(cellInputDate[1]+rowIndex).getValue(),
sheetDatabase.getRange(cellUpdateDate[1]+rowIndex).getValue()
];
for (var i=0; i<rangesToSetValues.length; i++) {
sheetData.getRange(rangesToSetValues[i]).setValue(values[i]);
}
}
function findInRow(id) {
var sheetDatabase = SpreadsheetApp.getActive().getSheetByName('Data');
var rows = sheetDatabase.getRange("A2:A").getValues();
for (var r=0; r<rows.length; r++) {
if ( rows[r][0] === id ) {
return r+2;
}
}
return -1;
}
function increaseId(id) {
if(id>0) {
var returnId;
returnId = id + 1;
return returnId;
}
}
function findMaxId(myvalues){
return Math.max.apply(null, myvalues);
}
function onOpen(e) {
//initialization
/*var sheet = SpreadsheetApp.getActive().getSheetByName('Form'); //var sheet = SpreadsheetApp.getActive().getSheetByName('Reception');
sheet.getRange(cellId[0]).setValue(1000);
clear_screen();*/
}
function onEdit(e) {
//e.source.setActiveSelection(e.range.offset(2, 0));
var sheet = SpreadsheetApp.getActive().getSheetByName('Form');
var rangeRowId = sheet.getActiveCell().getRow();
var rangeColId = sheet.getActiveCell().getColumn();
//Browser.msgBox("Row Id: " + rangeRowId + " Column Id: " + rangeColId );
if(rangeRowId == 3 && rangeColId == 10) {
var myId = sheet.getRange(cellId[0]).getValue();
lookUpId(myId);
}
}
function clear_screen() {
var sheet = SpreadsheetApp.getActive().getSheetByName('Form');
var rangesToClear = [cellStreetAddress[0], cellCity[0], cellState[0], cellZip[0], cellCounty[0], cellfiftyfive[0], cellIL[0],
cellAL[0], cellMC[0], cellBeds[0], cellPhase[0], cellLand[0], cellBuildable[0],
cellPrice[0], cellGrade[0], cellSource[0], cellClassification[0], cellSiteDescription[0], cellProjDescription[0],
cellSiteVisit[0], cellTeamsLink[0], cellGoogleMap[0], cellZoningClass[0], cellZoningDesc[0], cellEntitlements[0],
cellParkingType[0], cellConstType[0], cellUnitSizeRange[0], cellTotalSqFt[0], cellTotalCost[0], cellTotalCostDoor[0], cellTotalCostSF[0],
cellTotalDebt[0], cellTotalEquity[0], cellFDGEquity[0], cellCapitalStructure[0], cellDateProcessed[0], cellMarketStudyLink[0], cellPhotoLibrary[0], cellCoDev[0],
cellFeeDev[0], cellOperator[0], cellPartner[0], cellArchitect[0], cellEngineer[0], cellContractor[0], cellBroker[0], cellRezoning[0],
cellSitePlan[0], cellPlanPermit[0], cellClosing[0], cellExtensions[0], cellTimeToClose[0], cellEstConstStart[0], cellEstConstLength[0],
cellEstConstFinish[0], cellNotes[0], cellDropped[0], cellInputDate[0], cellUpdateDate[0]];
for (var i=0; i<rangesToClear.length; i++) {
sheet.getRange(rangesToClear[i]).clearContent();
}
var myCellStreetAddress = sheet.getRange(cellStreetAddress[0]);
myCellStreetAddress.activateAsCurrentCell();
}
function lookUpId(id) {
if (id==1000) { //Data Centre mode
clear_screen();
}
if (id>1000) { //lookup mode
getMember(id);
}
}
'''

Related

Issue with Google Apps Script code copy-paste from Gsheet file

I've created a code to copy-paste the values from the most recent uploaded Gsheet file to another. The code is supposed to copy-paste only values that fulfil a cell condition.
The problem is, this code takes to long to run and doesn't finish to copy all values before having a run-time error.
The file has about 300.000 cells and the final amounts to be pasted on the 2nd file have about 90.000 cells.
Does anyone have a recommendation on how to proceed?
Thank you so much for your kind support.
function Master_Run_DB() {
Copy_EUDB();
}
function Copy_EUDB() {
var myLink = extractLink_EUDB();
sendData_EUDB(myLink);
}
function extractLink_EUDB() {
var newData = new Date().toLocaleString();
var drive = DriveApp.getFolderById("link to file");
var file = drive.getFilesByType(MimeType.GOOGLE_SHEETS);
var link = file.next().getUrl();
var ss = SpreadsheetApp.getActiveSpreadsheet();
return link
}
function sendData_EUDB(link) {
var mainSS = SpreadsheetApp.openById("link to file");
var lastRow = mainSS.getSheetByName("Database").getLastRow();
mainSS.getSheetByName("Database").getRange("A2" + ":R" + lastRow).clearContent();
var baseSS = SpreadsheetApp.openByUrl(link);
Logger.log(SpreadsheetApp.getActiveSpreadsheet().getUrl());
var lRow = baseSS.getSheetByName("Sheet1").getLastRow();
for (var i = 2; i <= lRow; i++) {
var cell = baseSS.getRange("G" + i);
var val = cell.getValue();
if (val == "EU") {
var sourceData = baseSS.getSheetByName("Sheet1").getRange("A" + i + ":R" + i).getValues();
var to = mainSS.getSheetByName("Database").getRange("A" + i + ":R" + i).setValues(sourceData);
}
}
};
Hello again,
Now that the new code is working, I was trying to add an IF AND clause to the copy-paste. The objective would be to copy only values that fulfil the following condition:
Column 7 = "EU"
Column 11 <> "CCCC"
But I'm getting a Syntax Error. Any advice?
Thank you in advance for your kind support
function Master_Run_EU() {
var drive = DriveApp.getFolderById("link to file");
var file = drive.getFilesByType(MimeType.GOOGLE_SHEETS);
var link = file.next().getUrl();
var ss = SpreadsheetApp.openById("link to file");
const sh=ss.getSheetByName('Database');
sh.getRange(2,1,sh.getLastRow(),22).clearContent();
var dbss = SpreadsheetApp.openByUrl(link);
const dbsh=dbss.getSheetByName('Sheet1');
var oA=[];
var vs=dbsh.getRange(2,1,dbsh.getLastRow()-1,22).getValues();
vs.forEach(function(r,i){
if(r[7]=="EU" && r[11]<>"CCCC") {
oA.push(r);
}
});
sh.getRange(2,1,oA.length,oA[0].length).setValues(oA);
}
Try this:
function Master_Run_DB() {
var drive = DriveApp.getFolderById("1ViOyzIkGOI6G6SMrtmPv4vjL-2-2duHC");
var file = drive.getFilesByType(MimeType.GOOGLE_SHEETS);
var link = file.next().getUrl();
var ss = SpreadsheetApp.openById("13CchyoqiWyvGTnYuG5TWA4cggBS-FsoDkW8XGesDkiY");
const sh=ss.getSheetByName('Database');
sh.getRange(2,1,sh.getLastRow(),18).clearContent();
var dbss = SpreadsheetApp.openByUrl(link);
const dbsh=dbss.getSheetByName('Sheet1');
var vs=dbsh.getRange(2,1,dbsh.getLastRow()-1,18).getValues();
vs.forEach(function(r,i){
if(r[6]=="EU") {
sh.getRange(i+2,1,1,18).setValues([r]);
}
});
}
It would be faster to do it this way:
function Master_Run_DB() {
var drive = DriveApp.getFolderById("1ViOyzIkGOI6G6SMrtmPv4vjL-2-2duHC");
var file = drive.getFilesByType(MimeType.GOOGLE_SHEETS);
var link = file.next().getUrl();
var ss = SpreadsheetApp.openById("13CchyoqiWyvGTnYuG5TWA4cggBS-FsoDkW8XGesDkiY");
const sh=ss.getSheetByName('Database');
sh.getRange(2,1,sh.getLastRow(),18).clearContent();
var dbss = SpreadsheetApp.openByUrl(link);
const dbsh=dbss.getSheetByName('Sheet1');
var oA=[];
var vs=dbsh.getRange(2,1,dbsh.getLastRow()-1,18).getValues();
vs.forEach(function(r,i){
if(r[6]=="EU") {
oA.push(r);
}
});
sh.getRange(2,1,oA.length,oA[0].length).setValues(oA);
}

Looping backwards through data values

I am guessing my logic does not work do to the values I am using in the loop. Not quite sure how to proceed. Thank you.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ash = ss.getSheetByname("Master List C");
var laRow = ash.getLastRow();
var laCol = ash.getLastColumn();
var toMove = [];
var dsh = ss.getSheetByname("Non-Members");
var ldRow = dsh.getLastRow();
var ldCol = dsh.getLastColumn();
var range = ash.getRange(9, 1, laRow, laCol);
var aData = range.getValues();
for (row = aData.length; row >= 9; row--) {
if (aData[row][6] == "No") {
var tmp = [aData[row][0], aData[row][1], aData[row][2], aData[row][3], aData[row][4], aData[row][5], aData[row][8]];
toMove.push(tmp);
dsh.getRange(dsh.getLastRow() + 1, 1, toMove.length, 7).setValues(toMove);
ash.deleteRow(row);
}
}

Increase my script performance Google Sheets Script

I created a function that whenever I run the AppendRow script every row that does not have a dot (".") at the AY column, an array with every information/column that I want from that sheet will be transfered to my main sheet that has around 13k rows atm.
Usually about 20-40 rows get pasted into the first sheet everyday and this script automatically re-arranges the columns to my main sheet.
PROBLEM:
The problem is that each row that gets appended to my main sheet takes around 8-15sec to get transfered and sometimes I get this "exceeded-maximum-execution-time" error thats its really annoying.
Is there any way to make my code run faster or maybe just a way to make the script run more than 5 minutes?
function AppendRow() {
var app = SpreadsheetApp;
var Sheet = app.getActiveSpreadsheet().getSheetByName("Sheet1");
var ss2017 = SpreadsheetApp.openById("");
var sheet2017 = ss2017.getSheetByName("2017");
var lastSourceRow = Sheet.getLastRow();
var lastSourceCol = Sheet.getLastColumn();
var sourceRange = Sheet.getRange(1, 1, lastSourceRow, lastSourceCol);
var sourceData = sourceRange.getValues();
var lenght = sourceData.length;
//Logger.log(lenght);
var time = new Date();
time = Utilities.formatDate(time, "GMT+01:00", "dd/MM/yy, HH:mm:ss");
for(i=5326;i<=lenght;i++)
//my i=5326 is just cuz I had already
// information on my sheet that was transfered before this script existed
{
var columnAY = Sheet.getRange(i,51).getValue();
var checkReservation = Sheet.getRange(i,2).getValue();
if(columnAY == ".")
{
}
else
{
var B = Sheet.getRange(i,2).getValue();
var F = Sheet.getRange(i,6).getValue();
var E = Sheet.getRange(i,5).getValue();
var K = Sheet.getRange(i,11).getValue();
var L = Sheet.getRange(i,12).getValue();
var V = Sheet.getRange(i,22).getValue();
var O = Sheet.getRange(i,15).getValue();
var P = Sheet.getRange(i,16).getValue();
var Q = Sheet.getRange(i,17).getValue();
var AF = Sheet.getRange(i,32).getValue();
var AG = Sheet.getRange(i,33).getValue();
var N = Sheet.getRange(i,14).getValue();
var AI = Sheet.getRange(i,35).getValue();
var AB = Sheet.getRange(i,28).getValue();
var AC = Sheet.getRange(i,29).getValue();
var array = ["",B,F,E,K,L,"",V,O,P,Q,AF,AG,"","",N,N,AI,"","",AB,AC,"","","","",time];
sheet2017.appendRow(array);
Sheet.getRange(i,51).setValue(".");
}
}
}
p.s.: I also have a menu in my spreadsheet to run the script every time i want to not sure if that is any relevant to the question :P
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('My Menu')
.addItem('Copy to 2017', 'AppendRow')
.addToUi();
Every comment is appreciated !! :)
I must admit to having a bit of a problem figure out how my i's coordinated with your's but I think my columns are correct. So check it out but this should run a bit faster.
function AppendRow()
{
var ss0=SpreadsheetApp.getActive();
var sh0=ss.getSheetByName('Sheet1');
var rg0=sh0.getDataRange();
var vA0=rg0.getValues();
var ss1=SpreadsheetApp.openById(id);
var sh1=ss1.getSheetByName('2017');
var TimeStamp=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "dd/MM/yy HH:mm:ss");
for(i=5326;i<vA0.length;i++)
{
var columnAY=vA0[i][50];
var checkReservation=vA0[i][1];
if(vA0[i][50]!='.')
{
var B = vA0[i][1];//Sheet.getRange(i,2).getValue();
var F = vA0[i][5];//Sheet.getRange(i,6).getValue();
var E = vA0[i][4];//Sheet.getRange(i,5).getValue();
var K = vA0[i][10];//Sheet.getRange(i,11).getValue();
var L = vA0[i][11];//Sheet.getRange(i,12).getValue();
var V = vA0[i][21];//Sheet.getRange(i,22).getValue();
var O = vA0[i][14];//Sheet.getRange(i,15).getValue();
var P = vA0[i][15];//Sheet.getRange(i,16).getValue();
var Q = vA0[i][16];//Sheet.getRange(i,17).getValue();
var AF = vA0[i][31];//Sheet.getRange(i,32).getValue();
var AG = vA0[i][32];//Sheet.getRange(i,33).getValue();
var N = vA0[i][13];//Sheet.getRange(i,14).getValue();
var AI = vA0[i][34];//Sheet.getRange(i,35).getValue();
var AB = vA0[i][27];//Sheet.getRange(i,28).getValue();
var AC = vA0[i][28];//Sheet.getRange(i,29).getValue();
var array = ["",B,F,E,K,L,"",V,O,P,Q,AF,AG,"","",N,N,AI,"","",AB,AC,"","","","",TimeStamp];
sh1.appendRow(array);
sh0.getRange(i+1,51).setValue(".");
}
}
}

TyperError: Cannot read property "length" of undefined --- but it is defined?

Uncaught TypeError: Cannot read property 'length' of undefined
at buildTable (test.js:14)
at test.js:2
I'm not entirely sure what is happening here. I am getting this error, it seems like its saying my array is undefined, but it is defined?
edit: its referring to the code in the loop.
var table = document.getElementById("tableBody");
buildTable();
var toDoArray = [];
function buildTable(){
var retrievedTaskObject = localStorage.getItem("task");
var parsedObject = JSON.parse(retrievedTaskObject);
var addTheTaskName = parsedObject.taskName;
var addTheTaskDate = parsedObject.taskDate;
for(i=0; i < toDoArray.length; i++){
addTaskToTable(parsedObject[i]);
}
}
function addTaskToTable(obj){
var row = table.insertRow(0);
var cellName = row.insertCell(0);
var cellDate = row.insertCell(1);
var cellId = row.insertCell(2);
var cellCheck = row.insertCell(3);
cellName.innerHTML= obj.name;
cellDate.innerHTML= obj.date;
var checkStuff = "<input type='checkbox'>";
cellCheck.innerHTML = checkStuff;
}
function submitForm(name,date) {
var addTaskName = document.getElementById("taskName").value;
var addTaskDate = document.getElementById("dateTask").value;
var taskSomething = getTaskObj(addTaskName,addTaskDate);
toDoArray.push(taskSomething);
addTaskToTable(taskSomething);
var storedArray = JSON.stringify(toDoArray);
localStorage.setItem("task",storedArray);
};
function getTaskObj(taskName,taskData){
var taskObject = {
name: taskName,
date: taskData,
};
return taskObject;
}
keep this before you call builtTable function
var toDoArray = [];
like
var toDoArray = [];
buildTable();
you are calling funtion and using array before defining..

Angular JS range input issue

when the all corners range input is moved, the rest of the inputs work fine but when another corner range is moved the all corners move 1~3 pixels, what could be the issue here?
Demo here:
http://jsfiddle.net/g10fsxym/
code:
var myApp = angular.module('myApp', []);
myApp.controller('myAppCtrlr', function($scope) {
var allcorners = new Quantity(5);
var topLeft = new Quantity(5);
var topRight = new Quantity(5);
var bottomLeft = new Quantity(5);
var bottomRight = new Quantity(5);
$scope.brCorners = allcorners;
$scope.brTopLeft = topLeft;
$scope.brBottomLeft = bottomLeft;
$scope.brTopRight = topRight;
$scope.brBottomRight = bottomRight;
$scope.brTopLeftCorner = function() {
$scope.brTopLeft = topLeft;
}
$scope.brBottomLeftCorner = function() {
$scope.brBottomLeft = bottomLeft;
}
$scope.brTopRightCorner = function() {
$scope.brTopRight = topRight;
}
$scope.brBottomRightCorner = function() {
$scope.brBottomRight = bottomRight;
}
$scope.brAllCorners = function() {
$scope.brTopLeft = $scope.brCorners;
$scope.brTopRight = $scope.brCorners;
$scope.brBottomLeft = $scope.brCorners;
$scope.brBottomRight = $scope.brCorners;
}});
function Quantity(value) {
var qty = value;
this.__defineGetter__("qty", function() {
return qty;
});
this.__defineSetter__("qty", function(val) {
val = parseInt(val);
qty = val;
});}`
Just make a copy of $scope.brCorners (otherwise you are working with references, so when you change one variable the another is also changed).
Demo
$scope.brAllCorners = function() {
$scope.brTopLeft = angular.copy($scope.brCorners);
$scope.brTopRight = angular.copy($scope.brCorners);
$scope.brBottomLeft = angular.copy($scope.brCorners);
$scope.brBottomRight = angular.copy($scope.brCorners);
}

Resources