scripts

Asgardian

New Member
Joined
Dec 29, 2020
Messages
1
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
  2. Mobile
  3. 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

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:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top