I have pasted example below
code:
function ck() {
//assigning variables
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var lastrow = ss.getLastRow();
var valsr7 = sheet.getRange(lastrow, 3).getValue();
var valsr30 = sheet.getRange(lastrow, 4).getValue();
var valsrn = sheet.getRange(lastrow, 5).getValue();
var valINC7 = sheet.getRange(lastrow, 6).getValue();
var valINC30 = sheet.getRange(lastrow, 7).getValue();
var valINCn = sheet.getRange(lastrow, 8).getValue();
var service = sheet.getRange(lastrow, 2).getValue();
var now = new Date();
var wk = now.getWeek();
//now assigning values to variable
var A = valsr7;
var B = valsr30;
var C = valsrn;
var D = valINC7;
var E = valINC30;
var F = valINCn;
var AB = AB;
if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0 ){
MailApp.sendEmail({
to: "prathamesh.padosakar.ext#lafargeholcim.com",
subject : "Open Tickets Global-C&k-T2 - Week-"+wk+"",
htmlBody: "Dear ABC, "+
"<p>Not assigned to any one = "+C+""+
"<P> "+" "+
"<p>Not updated more than 7 Days = "+D+" "+
"<p>Not Updated more than 30 Days = "+E+""+
"<p>Not assigned to any one = "+F+""+
"<p> "+" "+
"<p>Best Regards,"+
"<br>Global Service Desk "+,
cc: "techno.pratham94#gmail.com"})
}
if(service == 'Global-Servicenow-Support-T2' && A == 0){
MailApp.sendEmail({
to: "prathamesh.padosakar.ext#lafargeholcim.com",
subject : "Open Tickets Global-C&k-T2 - Week-"+wk+"",
htmlBody: "Dear ABC, "+
"<p>Not Updated more than 30 Days = "+B+""+
"<p>Not assigned to any one = "+C+""+
"<P> "+" "+
"<p>Not updated more than 7 Days = "+D+" "+
"<p>Not Updated more than 30 Days = "+E+""+
"<p>Not assigned to any one = "+F+""+
"<p> "+" "+
"<p>Best Regards,"+
"<br>Global Service Desk "+,
cc: "techno.pratham94#gmail.com"
});
}
else {
}
if(service == 'Global-Servicenow-Support-T2' && B == 0){
MailApp.sendEmail({
to: "prathamesh.padosakar.ext#lafargeholcim.com",
subject : "Open Tickets Global-C&k-T2 - Week-"+wk+"",
htmlBody: "Dear ABC, "+
"<p>Not updated more than 7 Days = "+A+" "+
"<p>Not assigned to any one = "+C+""+
"<P> "+" "+
"<p>Not updated more than 7 Days = "+D+" "+
"<p>Not Updated more than 30 Days = "+E+""+
"<p>Not assigned to any one = "+F+""+
"<p> "+" "+
"<p>Best Regards,"+
"<br>Global Service Desk "+,
cc: "techno.pratham94#gmail.com"
});
}
else {
}
when i pass condition through if(service == 'Global-Servicenow-Support-T2' && A == 0) and if(service == 'Global-Servicenow-Support-T2' && B == 0) it gives me single output output or correct output . when i pass condition if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0 ) it give me output of all 3 conditions which are mention below.
if(service == 'Global-Servicenow-Support-T2' && A == 0) and if(service == 'Global-Servicenow-Support-T2' && B == 0) and if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0 )
Please help i want single output when i pass condition if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0 ).
Change condition
if(service == 'Global-Servicenow-Support-T2' && A == 0){
to
if(service == 'Global-Servicenow-Support-T2' && A == 0 && B != 0){
and change condition
if(service == 'Global-Servicenow-Support-T2' && B == 0){
to
if(service == 'Global-Servicenow-Support-T2' && B == 0 && A != 0){
Then you will have one output for if (service == 'Global-Servicenow-Support-T2' && A ==0 && B == 0 )
Related
I am trying to create a small laptop rental system in the Google Sheets which sends email depending on checkbox which is selected (checked).
Two emails which are sent are: 1. Approved and 2. Overdue.
Problem that I have with my attempt is that multiple emails are sent even to the users which already have received the approval email when approved checkbox is selected and that no user is receiving any overdue email when overdue checkbox is selected. Also I have a Trigger set up with On edit. Its been wrecking my head for a while now, an help, pointers are greatly appreciated.
function onCheckboxEdit(e) {
var source = e.source;
var sheet = source.getActiveSheet();
var range = e.range;
var row = range.getRow();
var column = range.getColumn();
console.log("column:: ", column);
var targetRange = sheet.getRange(row, 1, 1, 17);
var targetValues = targetRange.getValues();
console.log("targetRange:: ", targetValues);
var student = targetValues[0][2];
var recipient = targetValues[0][1];
var checkboxValue = targetValues[0][9];
var checkboxValue2 = targetValues[0][17];
var subject = ("Laptop Loan Approved");
var body = ("Hello "+ student +", \n\nWe are happy to confirm that your laptop loan application has been approved.");
var subject2 = ("Laptop Loan");
var body2 = ("Hello "+ student +", \n\nPlease disregard last e-mail sent by us, it was mistakenly sent.");
var subject3 = ("Overdue Laptop Loan");
var body3 = ("Hello "+ student +", \n\nThe laptop you have been loaned is due to be returned.");
if(column = 10 && checkboxValue == true) {
console.log("chekbox marked true")
MailApp.sendEmail(recipient, subject, body)
} else if (column = 10 && checkboxValue == false) {
console.log("chekbox marked false")
MailApp.sendEmail(recipient, subject2, body2)
} else {
console.log("No clue")
}
if(column = 18 && checkboxValue2 == true) {
console.log("chekbox marked true")
MailApp.sendEmail(recipient, subject3, body3)
} else if (column = 18 && checkboxValue2 == false) {
console.log("chekbox marked false")
MailApp.sendEmail(recipient, subject3, body2)
} else {
console.log("No clue")
}
}
if(column = 10 .........)
should be ...
if(column == 10 .........)
or even ...
if(column === 10 .........)
Thanks to JtrM we have an answer!
rrays are zero indexed. Rows and columns are not. var targetRange = sheet.getRange(row, 1, 1, 17); Change the 17 to 18 –
JtrM
Also adding extra (=) eg: Before column = 10 After column == 10 etc...
function onCheckboxEdit(e) {
var source = e.source;
var sheet = source.getActiveSheet();
var range = e.range;
var row = range.getRow();
var column = range.getColumn();
console.log("column:: ", column);
var targetRange = sheet.getRange(row, 1, 1, 18); // <- 17 changed to 18
var targetValues = targetRange.getValues();
console.log("targetRange:: ", targetValues);
var student = targetValues[0][2];
var recipient = targetValues[0][1];
var checkboxValue = targetValues[0][9];
var checkboxValue2 = targetValues[0][17];
var subject = ("Laptop Loan Approved");
var body = ("Hello "+ student +", \n\nWe are happy to confirm that your laptop loan application has been approved.");
var subject2 = ("Laptop Loan");
var body2 = ("Hello "+ student +", \n\nPlease disregard last e-mail sent by us, it was mistakenly sent.");
var subject3 = ("Overdue Laptop Loan");
var body3 = ("Hello "+ student +", \n\nThe laptop you have been loaned is due to be returned.");
if(column == 10 && checkboxValue == true) {
console.log("chekbox marked true")
MailApp.sendEmail(recipient, subject, body)
} else if (column == 10 && checkboxValue == false) {
console.log("chekbox marked false")
MailApp.sendEmail(recipient, subject2, body2)
} else if(column == 18 && checkboxValue2 == true) {
console.log("chekbox marked true")
MailApp.sendEmail(recipient, subject3, body3)
} else if (column == 18 && checkboxValue2 == false) {
console.log("chekbox marked false")
MailApp.sendEmail(recipient, subject3, body2)
} else {
console.log("No clue")
}
}
I have a spreadsheet with 4 columns that i am concerned with:
Group (Ferrous/Non-ferrous/etc.)
RI No. (Unique identifier)
Item Description (Name of the chosen RI No. item)
Supplier (Sellers of chosen RI No.)
The flow of data happens like this:
I select Group (say, Ferrous) --> In RI No. column, an automatic dropdown is created, showing RI Nos. of all items under Ferrous category show up --> I select a particular RI No. from this drop-down --> Item Description appears through VLOOKUP --> A drop-down of all sellers selling that item show up in in Supplier column.
Now, I wrote a code which does this work perfectly, but i was wondering if there was a way to make it so that:
I select Group (say, Ferrous) --> In RI No. column AND in Item Description column, an automatic dropdown is created, showing RI Nos. of all items under Ferrous category show up --> If I select RI No., item description gets populated/If I select Item Description, RI No. gets populated --> corresponding suppliers list show up as they do now.
Sample spreadsheet: https://docs.google.com/spreadsheets/d/16qv-OgCIezEuaOm8fQdq91FiQbBny4MzGRIho9ZCY-E/edit#gid=1605627126
The code:
var ws = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var wsopt = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sorted items");
var opts = wsopt.getRange(2,1,wsopt.getLastRow()-1,13).getValues();
var firstlevelcolumn = 2;
var secondlevelcolumn = 5;
var thirdlevelcolumn= 6;
var wsopt2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("supplier details");
var opts2 = wsopt2.getRange(3,1,wsopt2.getLastRow()-1,12).getValues();
function onEdit(e)
{ var activecell= e.range;
var val = activecell.getValue();
var r= activecell.getRow();
var c= activecell.getColumn();
var wsName= activecell.getSheet().getName();
if (wsName == "JPS")
{
if (wsName == "JPS" && c == firstlevelcolumn && r > 2)
{ applyFirstLevelValidation(val,r);}
if (wsName == "JPS" && c == secondlevelcolumn && r > 2)
{ applySecondLevelValidation(val,r);}
}//JPS
else if (wsName == "DDNI")
{
if (wsName == "DDNI" && c == firstlevelcolumn && r > 2)
{applyFirstLevelValidation(val,r);}
if (wsName == "DDNI" && c == secondlevelcolumn && r > 2)
{ applySecondLevelValidation(val,r);}
}//DDNI
}//close onEdiT
function applyFirstLevelValidation(val,r)
{
if(val=== "")
{
ws.getRange(r,secondlevelcolumn).clearContent();
ws.getRange(r,secondlevelcolumn).clearDataValidations();
ws.getRange(r,thirdlevelcolumn).clearContent();
ws.getRange(r,thirdlevelcolumn).clearDataValidations();
} else
{
ws.getRange(r,secondlevelcolumn).clearContent();
ws.getRange(r,secondlevelcolumn).clearDataValidations();
ws.getRange(r,thirdlevelcolumn).clearContent();
ws.getRange(r,thirdlevelcolumn).clearDataValidations();
var filteredopts = opts.filter(function(o){return o[0]===val});
var listToApply = filteredopts.map(function(o){return o[1]});
var cell=ws.getRange(r,secondlevelcolumn);
applyValidationToCell(listToApply,cell);
}//close else
}//close applyFirstLevelValidation
function applySecondLevelValidation(val,r)
{
if(val=== "")
{
ws.getRange(r,thirdlevelcolumn).clearContent();
ws.getRange(r,thirdlevelcolumn).clearDataValidations();
} else
{
ws.getRange(r,thirdlevelcolumn).clearContent();
ws.getRange(r,thirdlevelcolumn).clearDataValidations();
var firstlevelcolvalue = ws.getRange(r,firstlevelcolumn).getValue();
var filteredopts2 = opts2.filter(function(o){return o[6]===firstlevelcolvalue && o[4]===val});
var listToApply2 = filteredopts2.map(function(o){return o[0]});
var cell2=ws.getRange(r,thirdlevelcolumn);
applyValidationToCell(listToApply2,cell2);
}//close else
}
function applyValidationToCell(list,cell)
{
var rule = SpreadsheetApp.newDataValidation().requireValueInList(list).build();
cell.setDataValidation(rule);
}
Hi I want to show Onlt The first date entered, so whenever someone change it
the timestamp WONT change
what can i use for it? like filter?
my code is like this
if C&E&F is filled
then timestamp
the timestamp should be freezed once someone input it, when someone change it the timestamp WONT CHANGET
function onEdit(e) {
const editedRange = e.range
const sheet = editedRange.getSheet()
var row = editedRange.getRow();
if (
sheet.getName() === 'Data' && ///cari sheet yang dipakai
(editedRange.getColumn() == 4 || editedRange.getColumn() == 5 || editedRange.getColumn() == 6) && ///jika keisi
(sheet.getRange(row, 4).getValue() !== "" && sheet.getRange(row, 5).getValue() !== "" && sheet.getRange(row, 6).getValue() !=="") ///jika tidak diisi
)
{
const timestampRange = sheet.getRange(editedRange.getRow(), 1, editedRange.getNumRows(), 1)
timestampRange.setValue(Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "d/MM/yyyy HH:mm:ss")); /// memunculkan timestamp pada colum ke1/A yg dituju
}
}
This version requires that all three of d,e and f must be filled in order to get a time stamp and once you get a timestamp then it does not change unless the user changes it manually
function onEdit(e) {
//e.source.toast("Entry1");
const sh = e.range.getSheet()
if (sh.getName() == 'Sheet0' && e.range.columnStart > 3 && e.range.columnStart < 7 && e.value) {
let x = sh.getRange(e.range.rowStart,4,1,3).getValues()[0].every(e => e );//This requires d,e and f to be filled or truthy
//e.source.toast("outer gate " + x);
if (sh.getRange(e.range.rowStart, 1).getValue() == '' && x) {
//e.source.toast("inner gate")
sh.getRange(e.range.rowStart, 1).setValue(Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "d/MM/yyy HH:mm:ss"))
}
}//if column is null the set the timestamp otherwise do nothing
}
Demo:
I'm trying to use an if statement in scripts to set cell values once conditions are met, however its not working and i can't figure out why.
I need to do it using scripts rather than formulas in the sheet itself
var mainWSname = "Exposure"
function onEdit(e){
var activeCell = e.range();
var r = activeCell.getRow()
var c = activeCell.getColumn()
var val = activeCell.getValue();
var wsName = activeCell.getSheet().getName()
if(wsName === mainWSname && c === 2 && val === "Match"){
wsName.getRange(r, 3).setValue("18")
wsName.getRange(r, 4).setValue("80")
}
}
Try this modification:-
var mainWSname = "Exposure"
function onEdit(e){
var activeCell = e.range;
var r = activeCell.getRow()
var c = activeCell.getColumn()
var val = e.value;
var wsName = activeCell.getSheet()
if(wsName.getName() === mainWSname && c === 2 && val === "Match"){
wsName.getRange(r, 3).setValue("18")
wsName.getRange(r, 4).setValue("80")
}
}
Reference:
Event Object
I am attempting to have a script check sheet1 for first and last names (2 cells), use the first and last name of each person in sheet1, then in sheet2 check each person for a value in 4-5 rows greater than 0.
The issue is that certain names are in different columns and I need to check one column and have those names in that one column checked against a large (180 cells) list of names. This is the part where it times out.
I have the code fully functioning and working, but it uses some parts too heavily and ends up timing out. The getvalue function is used heavily and I am unsure of a better way to use it. I am looking for how to make it more efficient and or run better.
I may just have to input the names in the code to make it faster, but I was hoping for a more user-friendly approach so that names could change in sheet1 and format automatically in the script.
Thank you!
function getvalue(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2').getRange(CellName).getValues();
}
function getAdvisee(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1').getRange(CellName).getValues();
}
function teacher1() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var LastRow = ss.getLastRow();
var columns = 3;
var columnassignments = 3;
var columnEnrichment = 3;
var columnAmount = 3;
var advisoryStudent = getvalue('a' + columnEnrichment);
var studentEnrichment = getvalue('g'+ columnEnrichment);
var hours = Utilities.formatDate(studentEnrichment, 'EST', 'mm');
var minutes = Utilities.formatDate(studentEnrichment, 'EST', 'ss');
var teacherEmail = getAdvisee('b2');
var student1 = getAdvisee('b3');
var student1F = getAdvisee('b3');
var student2 = getAdvisee('b4');
var student2F = getAdvisee('b4');
var student3 = getAdvisee('b5');
var student3F = getAdvisee('b5');
var student4 = getAdvisee('b6');
var student4F = getAdvisee('b6');
var student5 = getAdvisee('b7');
var student5F = getAdvisee('b7');
var student6 = getAdvisee('b8');
var student6F = getAdvisee('b8');
var student7 = getAdvisee('b9');
var student7F = getAdvisee('c9');
var student8 = getAdvisee('b10');
var student8F = getAdvisee('c10');
var student9 = getAdvisee('b11');
var student9F = getAdvisee('c11');
var student10 = getAdvisee('b12');
var student10F = getAdvisee('c12');
var student11 = getAdvisee('b13');
var student11F = getAdvisee('c13');
for (columns; columns <= LastRow && columns <= 160; columns++) {
var advisoryStudent = getvalue('a' + columns);
var advisoryStudentSp = getvalue('b' + columns);
var reminderCount = getvalue('e' + columns);
var reminderLink = getvalue('m'+columns);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if ( getvalue('e' + columns) > 0 ) {
reminders = reminders + getvalue('b' + columns) + ' ' + getvalue('a' + columns) + ': ' + reminderCount + '<br>Reminder Link: ' + reminderLink + '<br>';
}
}
}
for (columnassignments; columnassignments <= LastRow && columnassignments <= 160; columnassignments++) {
var advisoryStudent = getvalue('a' + columnassignments);
var advisoryStudentSp = getvalue('b'+columnassignments);
var assignmentCount = getvalue ('f' + columnassignments);
var assignmentLink = getvalue('n' + columnassignments);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (getvalue('f' + columnassignments) > 0) {
assignments = assignments + getvalue('b' + columnassignments) + ' ' + getvalue('a' + columnassignments) + ': ' + assignmentCount + '<br>Assignment Link: ' + assignmentLink + '<br>';
}
}
}
for (columnAmount; columnAmount <= LastRow && columnAmount <= 160; columnAmount++) {
var advisoryStudent = getvalue('a' + columnAmount);
var advisoryStudentSp = getvalue('b' + columnAmount);
var amountowed = getvalue ('i' + columnAmount);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (getvalue('i' + columnAmount) > 0) {
amount = amount + getvalue('b' + columnAmount) + ' ' + getvalue('a' + columnAmount) + ': ' + '$' + amountowed + '<br>';
}
}
}
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Status Calculator');
var LastRow = ss.getLastRow();
var columns = 3;
var columnassignments = 3;
var columnEnrichment = 3;
for (columnEnrichment; columnEnrichment <= LastRow && columnEnrichment <= 160; columnEnrichment++) {
var advisoryStudent = getvalue('a'+columnEnrichment);
var advisoryStudentSp = getvalue('b' + columnEnrichment);
if (advisoryStudentSp == student1F || advisoryStudent == student2 && advisoryStudentSp == student2F || advisoryStudentSp == student3F || advisoryStudentSp == student4F || advisoryStudentSp == student5F || advisoryStudentSp == student6F || advisoryStudentSp == student7F && advisoryStudent == student7 || advisoryStudentSp == student8F || advisoryStudent == student9 && advisoryStudentSp == student9F|| advisoryStudent == student10 && advisoryStudentSp == student10F || advisoryStudent == student11 && advisoryStudentSp == student11F) {
if (Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'HH') > 0 || Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'mm') > 0){
enrichment = enrichment + getvalue('b' + columnEnrichment) + ' ' + getvalue('a' + columnEnrichment) + ': ' + Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'HH') + ' hours ' + Utilities.formatDate(getvalue('g' + columnEnrichment), 'EST', 'mm') + ' minutes <br>'
}
}
}
}
EDIT:
This portion just has a list of names in one column and searches for one word in the entire 200 row column and returns the rows with that word, then returns it again if it is greater than 5.
If I had it just looking for numbers greater than or equal to 5 and using a getvalue function, would that be the most efficient way to return names with values of 5 or more?
function getValues(CellName) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(CellName).getValues();
}
function setvalue(CellName, value) {
return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(CellName).setValue(value);
}
function test(i) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh2 = ss.getSheetByName('Sheet2');
var data = sh2.getRange('A1:C200').getValues();
var amount = sh2.getRange('c1:c200').getValues()
var findthis = sh2.getRange('e1').getValues();
var acol = sh2.getRange(1,sh2.getLastRow(),1,1).getValues();
var bcol = sh2.getRange(1,sh2.getLastRow(), 2, 1).getValues();
var test = acol.join().split(',');
var test2 = bcol.join().split(',');
for (i = 0; i<data.length; i++) { //search all rows
if ('wet' == data[i][0]) { //finds wet in the data column and returns row
Logger.log('testing' + ' row ' + (i+1))
if (amount[i][0] >= 5) { //search if c >= 5
Logger.log('Larger ' + ' row ' + (i+1))
}
}
}
}
I would suggest grouping your data into arrays by its natural grid ranges and then accessing the values by array index.
Something along the lines of:
function teacher1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh_1 = ss.getSheetByName('sheet1');
var sh_2 = ss.getSheetByName('sheet2');
...
// Get all related values into array & retrieve each row record by index
var student = sh_1.getRange("B3:C13").getValues(); // student[row][col] :ex: student11 => student[12][0]::student11F => student[12][1]
...
// remove the for loop & get all values in a col with one call per col
//(this could be optimized further)
var a_col = sh_2.getRange(1, sh_2.getLastRow(), 1, 1).getValues(); // col a rows 1-lastrow()
var b_col = sh_2.getRange(1, sh_2.getLastRow(), 2, 1).getValues(); // col b rows 1-lastrow()
// Flatten the array to make searching that column easier
var advisoryStudent = a_col.join().split(",")
var advisoryStudentSp = b_col.join().split(",")
// etc ...
// To check if student11 is in advisoryStudentSp: (can loop through students here)
// -1 means not found
// any other number is the index position of `advisoryStudentSp[i]`
// if 5 is returned then student11 matched the value in sheet2 colB row6
Logger.log("student11 is in position: %s", advisoryStudentSp.indexOf(student[12][0]))
}
edit: added the somewhat important .getValues()
Rather than retrieve the cell values one by one using your getValue() / getAdvisee() formulas you need to read the entire sheets or the relevant ranges all at once using Range.getValues(), then work with the data in the arrays.
The key issue here is that each individual call to Range.getValues() consumes a lot of time, whether you read in 100 cells at once or a single cell value. Thus your current approach of reading in one cell at a time is extremely slow (as you are seeing).
Refactoring in this way is too large to undertake as part of my answer, but once completed this script will run in just a couple seconds.