I have a apps script web form where I have a trigger event. When a user selects the ParcelID dropdown, it’s supposed to grab data from “Raw Data” and “Agent Notes” worksheet. It’s currently grabbing data from “Raw Data”, but the max comment from “Agent Notes” is not displaying at all.
heres the html side:
<label><strong>Parcel ID</strong></label><br>
<select name="parcelId" id="parcelId" onchange="updateMaxStatusAndLandownerInfo(this.value)">
<!-- Parcel ID dropdown will be populated dynamically -->
</select><br><br>
here’s the function in there too
function updateMaxStatusAndLandownerInfo(parcelId) {
updateMaxStatusForParcel(parcelId); // Call updateMaxStatusForParcel with the selected Parcel ID
getLandownerInfo(parcelId); // Call getLandownerInfo with the selected Parcel ID
}
here is the function in my code.js side:
function getLandownerInfo(landowner) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var rawDataSheet = ss.getSheetByName("Raw Data");
var commentsSheet = ss.getSheetByName("Agent Notes");
var headers = rawDataSheet.getRange(2, 1, 1, rawDataSheet.getLastColumn()).getValues()[0];
var lastRow = rawDataSheet.getLastRow();
var dataRange = rawDataSheet.getRange(3, 1, lastRow - 1, rawDataSheet.getLastColumn());
var values = dataRange.getValues();
var landownerInfo = "";
var maxComment = "N/A";
var maxCommentDate = "N/A";
var commentsDataRange = commentsSheet.getRange(2, 1, commentsSheet.getLastRow() - 1, commentsSheet.getLastColumn());
var commentsValues = commentsDataRange.getValues();
// Fetch the latest comment from Agent Notes
for (var k = commentsValues.length - 1; k >= 0; k--) {
if (commentsValues[k][0] == landowner && commentsValues[k][1]) {
maxCommentDate = Utilities.formatDate(commentsValues[k][2], Session.getScriptTimeZone(), "MM/dd/yy");
maxComment = commentsValues[k][1];
break;
}
}
// Include comments in landownerInfo
if (maxComment !== "N/A") {
landownerInfo += "Comments: [" + maxCommentDate + "] " + maxComment + "nn";
}
// Fetch and include data from Raw Data
for (var i = 0; i < values.length; i++) {
if (values[i][20] == landowner) {
var rowData = values[i];
for (var j = 0; j < headers.length; j++) {
if ([0, 1, 2, 3, 5, 6, 7, 8, 10, 20].indexOf(j) !== -1) {
landownerInfo += headers[j] + ": " + rowData[j] + "n";
}
}
break;
}
}
return landownerInfo;
}
any ideas what I am missing? I can’t seem to find anything out of place since the “Raw Data” data is coming over just fine into the form when the dropdown trigger occurs