[Solved] Time-in and Time-out

Shin

New member
I need help creating a program in which you can someone's id (with a barcode) and it automatically places it in the google sheet with the date, time, and action such as Time-In or Time-out, can anyone help me?
 
Hello Shin,

You can achieve this time in and time out using Google Apps Script.

Barcode Scanner: Use a USB barcode scanner (plug-and-play) or a mobile scanner app to input the ID into a Google Sheet.
Apps Script Automation: Use Google Apps Script to capture the scanned ID, date, time, and action (Time-In/Time-Out).
Google Apps Script:
JavaScript:
function recordScan(e) {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); // Update with your sheet name
  const scannedId = e.value; // This assumes the scanned ID is input into a cell
  const currentTime = new Date();
  const action = determineAction(scannedId); // Custom logic to toggle between Time-In/Time-Out
  sheet.appendRow([scannedId, currentTime, action]);
}

function determineAction(id) {
  // Logic to decide Time-In or Time-Out (can check the last entry of the same ID)
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
  const lastRow = sheet.getLastRow();
  const lastAction = sheet.getRange(lastRow, 3).getValue();
  return lastAction === 'Time-In' ? 'Time-Out' : 'Time-In';
}

Scanning the barcode automatically triggers the script to log the ID, date, time, and action.
 

Online statistics

Members online
0
Guests online
6
Total visitors
6

Forum statistics

Threads
384
Messages
1,682
Members
726
Latest member
Thurley
Back
Top