I am a very very beginner with script writing. Basically I've had a couple scripts written for me that I've been able to manage throughout the years. however a script that I've had running for years suddely stopped working. Nothing that I'm aware of has changed. ( honestly I don't know what im looking at to even recognize if something has) Please Please if there's anyone that can help it would be greatly appreciated. ReferenceError: ArrayLib is not defined (line 50, file "Code") Please please please
function OOU() {
var ss = SpreadsheetApp.openById("1L9f8wx3OYnry_UocEpBapuEmismMd6XYBO1Kl9e4duE");
var unitsoou = ss.getSheetByName("ROSS_OOU_Import")
var numRows = unitsoou.getDataRange();
var names = unitsoou.getRange(2, 4, 200).getDisplayValues();
var sheetName = PropertiesService.getScriptProperties().getProperty("1");
var unitSched = ss.getSheetByName(sheetName);
PropertiesService.getScriptProperties().setProperty("1", "UNIT_427")
var currentDate = Utilities.formatDate(new Date(), "GMT+1", "MM/dd/yyyy");
var changeDate = unitSched.getRange(4,38).getValue();
var newChangeDate = new Date(changeDate.getTime() + 3600000*24)
var newChangeDate = Utilities.formatDate(newChangeDate, "GMT+1", "MM/dd/yyyy");
if (newChangeDate == currentDate) {
var wp = unitSched.getRange(1,1).getValue();
wp = wp + 1
var newSheetName = "UNIT_" + wp
PropertiesService.getScriptProperties().setProperty("1",newSheetName)
unitSched = ss.getSheetByName(newSheetName)
}
unitSched.getRange(7,2,530,3).clearContent()
for (i =7; i <= 530; ++i) {
var name2 = unitSched.getRange(i, 40).getValue()
if (name2 != "#N/A" & name2 != "") {
var findName = ArrayLib.indexOf(names, 0, name2);
if (findName >= 0){
var incident = unitsoou.getRange(findName + 2 , 1).getDisplayValue()
var reqNumber = unitsoou.getRange(findName + 2, 3).getDisplayValue()
unitSched.getRange(i, 2).setValue("OOU")
unitSched.getRange(i, 3).setValue(incident)
unitSched.getRange(i, 4).setValue(reqNumber)
}
}
}
}
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Run ROSS OOU')
.addItem('ROSS OOU', 'OOU')
.addToUi();
}
Initially, I thought you made a typo but I just realized that you are using this external library: 2D Arrays Library.
Most likely you haven't installed the library for that script. Well, in that case you can follow the instructions in the link I provided and actually do it.
However, reading the documentation of this library, I found how ArrayLib.indexOf(names, 0, name2)
works:
Essentially you pass names
which is your 2D array (but in this case a column array), then you pass the index which is the column number to look for (in your case 0
column) and then name2
is the value to search for. Well, you don't need a library to do that. You can directly use the built in indexOf
method by yourself.
Replace:
var findName = ArrayLib.indexOf(names, 0, name2);
With:
var findName = names.flat().indexOf(name2);
Essentially, we flatten the array to make it 1D
so we can then work with indexOf directly and get the first index at which name2
appears in names
or get -1
if it is not present.
This will do exactly what the helper/library code would do and you don't depend anymore on this external library.
Assuming that the rest of your code works and as far as I can see, you are not using a method of this ArrayLib
library anywhere else, your code should be working fine after this modification.
Keep in mind that your code needs a lot of improvements as it is iteratively using API methods and it does not respect the Best Practices. However, the optimization of the code is not related to your question nor to this website (unless that is part of the solution itself). I would advice you to learn a little Google Apps Script so you can optimize your code, but also maintain/modify it when needed.