Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I want the below Google Apps script to run whenever a google search is made and it should update my google sheets page
- function addSearch() {
- // Access the active sheet
- var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
- // Get today's date
- var today = new Date();
- var formattedDate = Utilities.formatDate(today, "GMT+5:30", "yyyy-MM-dd");
- // Get the last updated date and search count from the sheet
- var lastUpdatedDate = sheet.getRange('A2').getValue();
- var searchCount = sheet.getRange('B2').getValue();
- // Calculate the time difference in hours
- var timeDifference = (today - lastUpdatedDate) / (1000 * 60 * 60);
- // If it has been more than 24 hours since the last update, add a new row with the current date
- if (timeDifference >= 24) {
- sheet.insertRowAfter(1);
- sheet.getRange('A2').setValue(formattedDate);
- sheet.getRange('B2').setValue(1); // Reset search count for the new day
- } else {
- // If it's the same day, increment the search count
- sheet.getRange('B2').setValue(searchCount + 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment