businessId = 27; // Big Dean's response = { "OK": false }; try { // Check if Big Dean's already has stations existing = queryExecute(" SELECT COUNT(*) as cnt FROM Stations WHERE StationBusinessID = :bizId ", { bizId: businessId }); if (existing.cnt == 0) { // Insert Kitchen station queryExecute(" INSERT INTO Stations (StationBusinessID, StationName, StationColor, StationSortOrder, StationIsActive) VALUES (:bizId, 'Kitchen', :color1, 1, 1) ", { bizId: businessId, color1: "##FF5722" }); // Insert Bar station queryExecute(" INSERT INTO Stations (StationBusinessID, StationName, StationColor, StationSortOrder, StationIsActive) VALUES (:bizId, 'Bar', :color2, 2, 1) ", { bizId: businessId, color2: "##2196F3" }); response["ACTION"] = "inserted"; } else { response["ACTION"] = "already_exists"; } // Get current stations stations = queryExecute(" SELECT StationID, StationName, StationColor, StationSortOrder FROM Stations WHERE StationBusinessID = :bizId AND StationIsActive = 1 ORDER BY StationSortOrder ", { bizId: businessId }); stationArr = []; for (s in stations) { arrayAppend(stationArr, { "StationID": s.StationID, "StationName": s.StationName, "StationColor": s.StationColor }); } response["OK"] = true; response["BUSINESS_ID"] = businessId; response["STATIONS"] = stationArr; } catch (any e) { response["ERROR"] = e.message; response["DETAIL"] = e.detail; } writeOutput(serializeJSON(response));