Asgardian
New Member
- Joined
- Dec 29, 2020
- Messages
- 1
- Office Version
- 365
- 2019
- 2016
- 2013
- 2011
- 2010
- 2007
- Platform
- Windows
- Mobile
- Web
I am currently working on a google script project.
I had made two scripts editing the same google sheet, but can not merge them together.
These are the scripts I used
OUT
IN
I had made two scripts editing the same google sheet, but can not merge them together.
These are the scripts I used
OUT
JavaScript:
var ss = SpreadsheetApp.openByUrl("Google Sheets - create and edit spreadsheets online, for free.");
var sheet = ss.getSheetByName("test");
function doGet(e){
var action = e.parameter.action;
if(action = "out")
return outTime(e);
}
function doPost(e){
var action = e.parameter.action;
if(action = "out")
return outTime(e);
}
function outTime(e){
var id = e.parameter.id;
var values = sheet.getRange(2,1,sheet.getLastRow(),1).getValues();
for(var i = 0 ; i<values.length ; i++){
if(values[0] == id){
i=i+2;
var out_time = Utilities.formatDate(new Date(), "IST", "HH:mm:ss");
sheet.getRange(i,4).setValue(out_time);
return ContentService.createTextOutput("Thank You ! Your out Time is "+out_time).setMimeType(ContentService.MimeType.TEXT);
}
}
return ContentService.createTextOutput("Id Not Found").setMimeType(ContentService.MimeType.TEXT);
}
IN
JavaScript:
var ss = SpreadsheetApp.openByUrl("Google Sheets - create and edit spreadsheets online, for free.");
var sheet = ss.getSheetByName("test");
function doGet(e){
var action = e.parameter.action;
if(action = "in")
return inTime(e);
if(action = "out")
return outTime(e);
}
function doPost(e){
var action = e.parameter.action;
if(action = "in")
return inTime(e);
if(action = "out")
return outTime(e);
}
function inTime(e){
var id = e.parameter.id;
var values = sheet.getRange(2,1,sheet.getLastRow(),1).getValues();
for(var i = 0 ; i<values.length ; i++){
if(values[0] == id){
i=i+2;
var in_time = Utilities.formatDate(new Date(), "IST", "HH:mm:ss");
sheet.getRange(i,3).setValue(in_time);
return ContentService.createTextOutput("Your In Time is "+in_time).setMimeType(ContentService.MimeType.TEXT);
}
}
return ContentService.createTextOutput("Id Not Found").setMimeType(ContentService.MimeType.TEXT);
}
Last edited by a moderator: