Danial Asraf Norbee
Danial Asraf Norbee

Reputation: 271

How to get active row number based from latest timestamp?

I'm using Google Form to collect data of my clients. An e-mail will be automatically sent out to the user with pre-filled information for them to review. However, whenever a user edit the form, the pre-filled information will extract the information from the last row.

I know why it happened because I used the e.values so it will always take the latest data/last row.

var firstName = e.values [1];

Is there another way to select the latest row just by looping, comparing all timestamps (first column ---> var time = e.values [0]; ) and select the latest row.

I have tried below code to get the active row but it did not work.

var lastActiveRow = firstsheet.getActiveRange().getRow()-1

I still haven't figure out how to get the latest timestamp/row.

Upvotes: 0

Views: 202

Answers (1)

Wicket
Wicket

Reputation: 38424

getActiveRange returns the range that is active, meaning that it's highlighted.

The latest timestamp position usually is the last row with data but this isn't deterministic because the data could be sorted/rearranged. If you want the last submitted response, look for the largest (newer) timestamp.

First we should get the column with the timestamps, then We could use JavaScript to find the most recent timestamp

What is the elegant way to get the latest date from array of objects in client side?

Upvotes: 0

Related Questions