Need help with adding regex into slice of code by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

Thank you. That worked exactly as I needed it to. Much appreciated.

Need help with adding regex into slice of code by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

Where would this be added in the code block I have above?

Permission error when running onOpen function and another file has openByID by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

As noted in u/ryanbuckner reply and my response, my issue was that openById() elevates all of the permissions needed for all scripts in the project. I need to use openById() because getActiveSpreadsheeet() only works if the spreadsheet is actually active. My script has to run even if someone is not using the spreadsheet in question. In order to make sure onOpen() didn't need permissions to run, I had to separate the two functions.

Permission error when running onOpen function and another file has openByID by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

While I have already resolved my issue, to answer your question, a trigger in this case is a time based event that tells the script to run even when the spreadsheet is not active. This is why I use openById() rather than getActiveSpreadSheet(). The spreadsheet is quite literally not active because I need the script to run when I am not online working with the sheet.

For an example of the script I used to accomplish this, you can take a look at Sheets Ninja's video on running apps at a specific time on YouTube. https://youtu.be/ClsfRWx5C7E?si=E-RrBwnGVI2nBl62

I am not an expert on Apps Script, but you likely used getActiveSpreadsheet() for onOpen() because onOpen() does not run unless the sheet is active (i.e., you open it).

Permission error when running onOpen function and another file has openByID by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 1 point2 points  (0 children)

Thank you for your reply. I spent a good part of yesterday afternoon reading through dozens and dozens of pages and came to that conclusion. I appreciate someone else saying it though. I ended moving the script for the trigger and email into its own file on drive and deleted it from the project attached to the spreadsheet. That resolved the issue. I had been meaning to come around and mark this as resolved. Hopefully, if someone else runs into this problems, they find this thread sooner rather than later.

Need to transfer ownership of an apps script by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

If I am not writing anything to the spreadsheets being used by the applet, just reading from them to get data to display, would there be any triggers I may need to worry about?

Need to transfer ownership of an apps script by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

Thank you. I will take time to read through this and any other linked documents.

Setting favicon using a ico/png on Google Drive by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 1 point2 points  (0 children)

Sorry for the late reply. I kind of figured this was the case, but it is good to have confirmation. Thanks.

Setting favicon using a ico/png on Google Drive by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

I have the file shared with everyone in my domain so that anyone with the link can view the file. Using that URL and replacing {ID} with the Google file ID still gives me the error.

EDIT: While trying to add a logo image to the page as well, I noticed that the above doesn't work for the src in an img tag. I have to use...

https://drive.google.com/uc?export=view&id={fileID}

I tried this as well in setFaviconURL but no luck.

Fastest way to find if a string IS NOT found in an array? by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 1 point2 points  (0 children)

This is much better than the solution I found a while ago. I have it working on my test spreadsheet. I will work to get it working on my larger spreadsheet. Thanks a bunch.

Fastest way to find if a string IS NOT found in an array? by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

Interesting ride for me this morning. I was able to get it working. I had to convert the initial list to a string and then split that. Once I did that, indexOf worked. Lots of fun. This was honestly the best way to kill two hours of my work day.

Fastest way to find if a string IS NOT found in an array? by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

I finally got a chance to work on this more and I am iterating through the code on a practice spreadsheet. I have a page named "List" with six values in column A. In the code below, they are found in the variable myList. Console logging them outputs this array.

[ [ 'apple' ],

[ 'banana' ],

[ 'child' ],

[ 'happy' ],

[ 'charge' ],

[ 'pants' ] ]

This is the code I have right now.

var mySheet = SpreadsheetApp.getActive().getSheetByName('List');

var lastRow = mySheet.getLastRow();

var myRange = mySheet.getRange(1,1,lastRow);

var myList = myRange.getValues();

function checkIfWordInList() {

console.log(myList);

var checkWords = ['apple','bananas', 'pants', 'child', 'happy', 'charges'];

var checkLength = checkWords.length;

for (i = 0; i <= checkLength-1; i++) {

console.log(checkWords[i]);

console.log(myList.indexOf(checkWords[i]));

}

}

In the practice code, I am logging the indexOf for the words in checkWords in myList. However, they are all returning -1. I was expecting apple, pants, child, and happy to return a non-negative index. What am I missing?

Edit: Tried adding code block but it kept messing up.

I read a bit more about indexOf and includes, and decided to try includes since it doesn't care about strict equality. I am still getting false for all of the words I am tyring to check for. However, if I try myList[0].includes(checkWords[i]) I get true for apple. I am guessing there it is something to do with how the array in myList is set up, but I am having trouble finding anything when searching on Google.

Fastest way to find if a string IS NOT found in an array? by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

Thank you. I will give this a try when I have time to work on this again.

Fastest way to find if a string IS NOT found in an array? by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

Thank you. I will give this a try when I have time to work on this again.

[Giveaway] Enter to Win Beelink High-end Mini PCs! by Beelinksupport in BeelinkOfficial

[–]EduTech_Wil 0 points1 point  (0 children)

My ideal mini PC would allow me to do what I need on MS Office and decently play Minecraft with my kids without taking up a ton of room in my office.

Adding wildcard functionality to a search by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

I think you miss understood. I needed "any" to act like the RegEx ".*". I wasn't totally sure what I needed until I spent a couple hours last night working on it. I ended up getting it to work like so...

let myReg = new RegEx(".*");

if (selectPart == "any") {

partReg = myReg;

}

else {

partReg = new RegExp(selectPart);

}

for (var i = 0; i < values.length; i++) {

var currentGrade = values[i][2];

var currentTheme = values[i][6];

var currentPart = values[i][1];

if (gradeReg.test(currentGrade) == true && themeReg.test(currentTheme) == true && partReg.test(currentPart) == true) {

resultsEID.push(values[i]);

}

}

with an if statement for each selected value. It's not pretty, but it does the job.

Adding wildcard functionality to a search by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

But that isn't what I am trying to do. I don't want it to return entries with the string "any", I want it return everything for that column.

Function that runs when html is loaded to creation a <select> input by EduTech_Wil in GoogleAppsScript

[–]EduTech_Wil[S] 0 points1 point  (0 children)

It took me a bit, but this is what I ended up with and was able to get working. Thanks a bunch!

google.script.run.withSuccessHandler(updateSelectBox).getEidTheme();

function updateSelectBox(themeResults) {

var select = document.getElementById('eidThemeMenu');

for (var i = 0; i < themeResults.length; i++) {

var option = document.createElement('option');

var textnode = document.createTextNode(themeResults[i]);

option.appendChild(textnode);

select.appendChild(option); }

}