KiKu
KiKu

Reputation: 377

How to perform lookup type function in google/Javascript

How to perform lookup type function in google/Java Script

I have user attendance data base in google sheet from their pull the today's entries using below formula

=QUERY(Sheet1!A1:K1000,"Select* Where J=toDate( now())")

and then to print the message I have used the following formula

=if(B1="Check-in","Last time you Clocked-In,You need to Check Out","Please Check- In")

I have created an HTML web app and generate current user email address using function getCurrentUserEmail() then I from all above function in google sheet Output I use to print in HTML web app.

Instead, can I perform all these activities using some simple google script

Upvotes: 1

Views: 294

Answers (1)

user6655984
user6655984

Reputation:

Get the data with getValues and process it, for example, with filter and map methods. An example, returning all rows in A-B columns where the date in B is today (or later):

var sheet = SpreadsheetApp.getActiveSheet();
var today = new Data();
today.setHours(0, 0, 0, 0); 

var range = sheet.getRange("A:B");
var data = range.getValues();
var result = data.filter(function(row) {
  return row[1] >= today;
});

if (result.length) {
  sheet.getRange(2, 10, result.length, result[0].length).setValues(result);
}

The output is placed in the same sheet starting with row 2 column 10; presumably you have something else to do with the lookup result within the script.

Upvotes: 1

Related Questions