initial working version

This commit is contained in:
Ben Miller
2024-11-04 01:06:00 -07:00
parent b2af2fc98c
commit 0fd89bc9ea
73 changed files with 38650 additions and 4 deletions

View File

@ -1,3 +0,0 @@
function myFunction() {
}

42
src/newSku.ts Normal file
View File

@ -0,0 +1,42 @@
function newSku(e: GoogleAppsScript.Events.SheetsOnEdit) {
var sheet = SpreadsheetApp.getActive().getActiveSheet()
if (sheet.getName() !== "product_inventory") {
console.log("skipping edit on sheet " + sheet.getName())
return
}
var row = e.range.getRow()
var idCell = sheet.getRange(row, 16).getCell(1, 1)
var idCellValue = idCell.getValue()
var skuPrefixCell = sheet.getRange(row, 15).getCell(1, 1)
var skuPrefixCellValue = skuPrefixCell.getValue()
console.log("skuPrefixCellValue = '" + skuPrefixCellValue + "'")
console.log("idCellValue = '" + idCellValue + "'")
if (idCellValue != "?" && idCellValue != "n") {
console.log("new ID was not requested, returning")
return
}
var idArray = sheet.getRange(2, 9, sheet.getLastRow(), 1).getValues()
var regExp = new RegExp(`^` + skuPrefixCellValue + `-0*(\\d+)$`)
console.log("regExp: " + regExp.toString())
var maxId = 0
for (let i = 0; i < idArray.length; i++) {
console.log("checking row " + (i + 1))
if (null == idArray[i] || String(idArray[i]) == "") {
console.log("ID cell looks null")
continue
}
console.log("ID cell: '" + idArray[i] + "'")
var match = regExp.exec(String(idArray[i]))
if (null === match) {
console.log("ID cell did not match")
continue
}
let numId = Number(match[1])
console.log("match: '" + match + "', numId: " + numId)
maxId = Math.max(numId, maxId)
console.log("numId: " + numId + ", maxId: " + maxId)
}
let newId = maxId + 1
console.log("newId: " + newId)
idCell.setValue(newId)
}

5
src/onEdit.ts Normal file
View File

@ -0,0 +1,5 @@
/// <reference types="@types/google-apps-script" />
function onEdit(e: GoogleAppsScript.Events.SheetsOnEdit) {
newSku(e)
}

8
src/tsconfig.json Normal file
View File

@ -0,0 +1,8 @@
{
"compilerOptions": {
"lib": [
"esnext"
],
"experimentalDecorators": true
}
}