I am hoping to generate a spreadsheet with details on items for my friend and me, such as selling price, cost, and status (Sold, in the sale, etc). I am aiming to automate the "status" column by incorporating dropdown menus with options like "Sold!", "waiting for sale..." and Null
. After writing code that changes the status based on specific dates (transitioning to "waiting for sale" if there's an upcoming on-sale date or to "Sold!" if a sold date is present), I encountered difficulties applying it to every row/column.
The script is working correctly when applied to individual rows; however, the actual sheet data remains unchanged. Here is the code:
function AutoStatus() {
let sheet = SpreadsheetApp.getActive().getSheetByName("Clean");
let data = sheet.getDataRange().getValues();
for (n = 0; n < data.length; ++n) {
let startDate = data[n][1];
let soldDate = data[n][2];
let status = data[n][6];
if (startDate != "" && soldDate >= startDate) {
status = "Sold!";
} else if (startDate != "") {
status = "Waiting for Sale...";
} else {
status = "Null";
}
console.log(startDate, soldDate, status)
}
}
The console log displays the following:
02:10:47 Info Execution Started
02:10:50 Info Start Date Sold Date Status
02:10:50 Info Wed Jun 19 2024 00:00:00 GMT+0200 (Central European Summer Time) '' 'Waiting for Sale...'
02:10:50 Info Thu Jun 20 2024 00:00:00 GMT+0200 (Central European Summer Time) Thu Jun 20 2024 00:00:00 GMT+0200 (Central European Summer Time) 'Sold!'
...
02:10:48 Info Execution Ended
Despite the console log indicating the correct status changes, the sheet does not reflect these updates (as shown in this Image of the sheet). I have been struggling with this issue for some time now and would greatly appreciate any assistance. Thank you!