I am having trouble with auto incrementing numbers in my googlesheet. Here is what I'm trying to do.
I created a googlesheet for issue tracking. The columns are Issue Status, Group, Issue Number, Priority, etc.... Issue Status is a drop down list with values OPEN and CLOSED. When I select OPEN from the drop-down list I want the ISSUE NUMBER to automatically display in the Issue Number column for that row.
For Example..... I have an empty issue log. I report the first issue by selecting OPEN in the ISSUE STATUS column. The number 1 should automatically populate in the Issue Number column for the first issue.
I report the 2nd issue by selecting OPEN on the next row. The number 2 should automatically populate in the Issue Number column for the second issue.
I report the 3rd issue by selecting OPEN on the next row. The number 3 should automatically populate in the Issue Number column for the second issue.
Currently I am manually entering the number. I want it to automatically populate when selecting OPEN from the list.
The line of code that I'm trying to use for this does not work as I want it to. In my case statement for OPEN, I added the following line
SpreadsheetApp.getActiveSheet().getRange('C5').setValue(SpreadsheetApp.getActiveSheet().getRange('C5').getValue() + 1);
Here's my code:
function onEdit(event)
{
var ColA = 1; // Column Number of "A"
var ColN = 14; // Column Number of "N"
var ColO = 15; // Column Number of "O"
var ColP = 16; // Column Number of "P"
var changedRange = event.source.getActiveRange();
if (changedRange.getColumn() == ColA && changedRange.getSheet().getSheetName() == "Issues")
{
// An edit has occurred in Column A
var state = changedRange.getValue();
var user = Session.getActiveUser().getEmail().substring(0, 2).toUpperCase();
var DateOpened = event.source.getActiveSheet().getRange(changedRange.getRow(),ColA+9);
var DateClosed = event.source.getActiveSheet().getRange(changedRange.getRow(),ColA+10);
var Iteration1 = event.source.getActiveSheet().getRange(changedRange.getRow(),ColA+13);
var Iteration2 = event.source.getActiveSheet().getRange(changedRange.getRow(),ColA+14);
var Iteration3 = event.source.getActiveSheet().getRange(changedRange.getRow(),ColA+15);
var d = new Date();
var timestamp = user + "_" + d.dateNow() + "_" + d.timeNow() + "\n";
// Determine the state of Col A
switch (state)
{
case "OPEN":
SpreadsheetApp.getActiveSheet().getRange('C5').setValue(SpreadsheetApp.getActiveSheet().getRange('C5').getValue() + 1);
// Write timestamp in Date Opened column
DateOpened.setValue(timestamp);
Iteration1.setValue("NOT EXECUTED");
Iteration2.setValue("NOT EXECUTED");
Iteration3.setValue("NOT EXECUTED");
break;
case "CLOSED":
// Write timestamp in Date Closed column
DateClosed.setValue(timestamp);
break
}
}
Any suggestions?