About the WebApp
Basically what the webapp does is to verify and check if a user's status is "arrived", "not yet here", or "unauthorized" then collect information if applicable.
The webapp contains an input box, read-only input box, div-alert and two buttons (verify & submit).
The person enters his/her ID, clicks verify and returns a feedback message in the read-only input box.
My Google Sheet have two worksheets:
a.) Sheet1 is a database with three columns. (Unique ID | Name | Status)
b.) Sheet2 contains a record of people that came that day. (TimeStamp | Unique ID | Name )
If he has an "Arrived" status, the form will return a message "This id have logged in already". If he has a "Not yet arrived" status, the form will return his 'Name', record his entry in Sheet2 upon clicking Submit button and updates Sheet1 status from "not yet here" to "arrived". If he is "Unauthorized" or his ID doesn't exist in the database, the form will return a message "Unauthorized or no matching record".
Client-Side
function checkID(){ var id = document.getElementbyID('id'); var idcheck = id.value; var match = idchk.match(/^[A-Z0-9-]{5,16}$/) ? "true": "false"; if( match == "false" ){ id.classList.add('is-invalid'); } else { google.script.run.withSuccessHandler(searchResult).idSearch(idcheck); } } function searchResult(msg){ var feedback = document.getElementbyID('feedback').value; if(msg[0] == "1" || msg[0] == "2" || msg[0] == null){ if (msg == "1"){ feedback = "This id have logged in already"; } else { feedback = "Unauthorized or no matching record"; } } else { feedback = msg; //display submit button } } getElementbyID('btnSubmit').addEventListener("submit", RecordData); function RecordData(){ var id = document.getElementbyID('id').value; var feedback = document.getElementbyID('feedback').value; var arry = {uid: id, pname: feedback } google.script.run.withSuccessHandler(alertNotif).newRecord(arry); } function alertNotif(msg){ //display alert success message ; } Server-side
function idSearch(uid){ try{ LockService.getScriptLock().waitLock(5000); } catch(e){ LockService.getScriptLock().releaseLock(); return false; } var ss = SpreadsheetApp.openById(spreadsheetID); var ws1 = ss.getSheetByName(Sheet1); var dataRange1 = ws1.getRange(2,1, ws1.getRange('A2').getDataRegion().getLastRow()-1, 3); var getData1 = dataRange1.getValues(); var match = getData1.filter(row => row[0] === uid).map(chkId); Utilities.sleep(2000); //<-----------------SHOULD I PAUSE?? return match; SpreadsheetApp.flush(); LockService.getScriptLock().releaseLock(); } function chkId(row){ if(row[2]=="Not yet arrived"|| row[2]=="Arrived"){ if (row[2]=="Arrived") { return row[1]; }else{ return "1"; } } else { return "2"; } } function newRecord(arry){ var ss = SpreadsheetApp.openById(spreadsheetID); var ws2 = ss.getSheetByName(Sheet2); ws2.appendRow([new Date(), arry.uid, arry.pname]); return "Please proceed to North Hall E-104"; } Issue
I am collecting other information such company name etc. but my issue is on retrieving the Name of the person only. Sometimes the (Name) of the person is just blank when appended to Sheet2.
没有评论:
发表评论