I currently use a Google Form to gather information from employees who work in remote locations
Emp No *
Punch *
Customer details / mode or travel
All the data collected is stored in a Google spreadsheet structured as follows:
Timestamp Emp No Punch Remark Name GeoCode GeoAddress Email
With a certain script, I am able to capture the GPS coordinates of the users. I created a web app where anyone, even without an account, can access it and click the link.
However, there are a few issues I am facing:
I wish to store the email ID (or employee number) of the user filling out the form. Unfortunately, the email ID does not get captured. It only works when I fill out the form myself. How can I capture this information for all users without requiring them to authenticate the script?
If the GPS information is missing (empty), I want to display a different message on the HTML page. Is there a way to do this?
Below is the relevant code:
function doGet() {
return HtmlService.createHtmlOutputFromFile("Index");
}
//
function getLoc(value) {
var destId = FormApp.getActiveForm().getDestinationId() ;
var ss = SpreadsheetApp.openById(destId) ;
var respSheet = ss.getSheetByName("Location");
var numResponses = respSheet.getLastRow();
var currentemail = Session.getActiveUser().getEmail();
var c=value[0]; var d=value[1];
var e=c + "," + d ;
//respSheet.getRange(numResponses,6).setValue(e);
//respSheet.getRange(numResponses,8).setValue(currentemail);
var response = Maps.newGeocoder().reverseGeocode(value[0], value[1]);
var f= response.results[0].formatted_address;
//respSheet.getRange(numResponses,7).setValue(f);
respSheet.getRange(numResponses,6,1,3 ).setValues([[ e, f, currentemail ]]);
}
//
index.html
<!DOCTYPE html>
<html>
<script>
(function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
})()
function showPosition(position){
var a= position.coords.latitude;
var b= position.coords.longitude;
var c=[a,b]
getPos(c)
function getPos(value){
google.script.run.getLoc(value);
}
}
</script>
<body>
<p>Please ensure your GPS is on to record your location. You can generate the report from website to check. Pl. close this window (version 3)</p>
</body>
</html>