Script to apply formulas to cell drop-down - google-apps-script

I am making a status tracker sheet that has a column for the status of each task. Right now, Column D is has the status for each task and is set up with a drop down menu:
No action needed
Needs attention
In progress
Complete
Column E has the due date for each task.
Is there a way to write a script for the drop down menu that will change the status of cells that say "No Action Needed" to "Needs attention" once the due date is within a week of the current date?
Also, what's the best way to incorporate email notifications into the script so that any time a status changes to "Needs attention", an email is sent to the owner in Column F?

This would definitely be possible through the built-in script editor.
Overall you would want to be able to interact with the sheet that this is data is stored in. The easiest way to do this is through the SpreadsheetApp class and methods.
For the first step, you would want to set up a script that checks whether the due date is within a week of the current date. This can be done using the Javascript Date Methods which can easily be compared using regular number operations such as subtraction and addition.
The second part of the script would be possible using the built-in apps script functions of MailApp.
When you have both of these parts of the scripts down, you should tie it to a trigger to ensure that the script will trigger at either given times (time-driven triggers) or at given events (event-triggers).

Related

Script to record a cell value remotely before it is erased by a constantly updating program Google Sheets

*Let's start with the Set-up. I am working on a program that assigns employees inspections based on who is the closest from their last job. The issue however it this program uses the TODAY function, which constantly updates. This wouldn't be a problem except once it is no longer TODAY, the optimization loop I've created pulls new values, meaning that jobs now previous to the current date will show as blank in the inspector column. In other words, once a date moves into the past we will have no record of who was assigned to it, which makes following up very difficult.
Here is what I need help to make happen.
At 5pm, I want cells in column E to take a snapshot of the value of the corresponding cells in column D for dates that equal TODAY.
Ideally I want this to be a custom function so I can make it dependent on the cell reference of the date code for TODAY.
(Such As in Cell E2: IF(B2=TODAY,"CUSTOM FUNCTION CAUSING SNAPSHOT of D2 Triggering # 5pm"," ")*
Schedule Sheet Picture
This is the problem I was seeking to solve. I after over a week of unassisted work, I was able to do what other posts and users deemed impossible without using App Scripts.
SOLUTION, ENTERED IN COLUMN P
=IF(O13="Automatic",IF($X$4<=L13+$Z$4,N13,P13),O13)
Column O gives me control of whether Column P displays the Automatically assigned inspector (Column N), or if it uses a Manually selected one, located in a dropdown menu of Column O.
X4 is a cell reference to a NOW() Function
Column L allows only dates
Z4 is a cell reference to a trigger time, which can be updated to any valid time.
Also note: To make this work, the spreadsheet settings must be adjusted. Make sure the timezone is correct. Enable iterative calculations. And set the spreadsheet to update on edit and by the minute.
All of this comes together to form a cell reference that will defer to the manual assignment when used, but will otherwise actively reflect the contents of the corresponding cell in column N until the trigger time, where in the code loops back on itself, resulting in a snapshot of the value that remains even after the program erases the values in column N

get sheet data without the hidden columns

I am currently working on GAS project, for the moment I have a table in a sheet and the idea is that my collaborators will be able to choose the format of the table, which column and which row they want to save. I thought about using the hiding column and row features but is it possible in my apps script to get only the data which they chose to save and not the hidden data ? Thank you for you answers
Apps Script works analogously to the Sheets UI
Explanation
If from the user interface you select the desired data by "click&drag", the hidden columns located between the start and the end column will be also selected (and copied). Instead you need to select the data of interest manually with "Ctrl" and click, see here.
How to transfer this to Apps Script?
Apps Script features the method sheet.isColumnHiddenByUser(columnPosition) (and isRowHiddenByUser, isRowHiddenByFilter etc.). You can use it to select only the ranges / the values of a datarange in columns and rows that are not hidden.
This implies the implementation of loops and conditions statements, so is not necessary an elegant solution.

How to disable editing of cells after midnight in googlesheet?

I have a google spreadsheet which we use to feed inventory purchase and issue data. The only problem is my staff can manipulate purchased quantity, prices and other variables at a later date. I want that if they enter data in a cell, they cannot edit it post-midnight but I can.
Also, I have filled most of the cells with formula, for example- there is formula in A1:H999, so that when they enter data, it calculates the values in other cells, and suppose my staff has entered data till A1:H500. In this case, the script should work On A1:H500, it should not consider the whole range just because i have filled it with formula. Thanks
If you want to limit access to the script to particular hours it's fairly simple. This can be done with one function if written in a clever way or with 2 functions.
Function1 will simply lock the spreadsheet and allow only you to edit by using the protection class, then use function2 (or write function1 in a clever way to do different things depending on when it starts) that is triggered at a different time to remove that protection.

IFFT Populated Google Spreadsheet Log Does not Trigger onEdit Script

I have a Google Spreadsheet that IFTTT adds a line to when particular events occur. I would like a Google script to run each time a line is added. Currently, the script has an installed onEdit trigger but it isn't triggered unless I manually edit the spreadsheet.
This thread and this thread describe similar issues but I lack the knowledge to try out their proposed solutions. The first suggests using a webapp and the second suggests using a time based trigger and checking for changes in the spreadsheet.
Any guidance would be greatly appreciated.
Further Details
Each row that comes in via IFTTT represents a purchase of a random prize. One column contains the price of the purchase, another column contains the date of the purchase, and another contains purchase details. When the total amount spent changes, the spreadsheet fetches a random number and the prize associated with the number. I want those details emailed to me when a prize is bought (more specifically, I want them emailed to IFTTT so it can SMS me the details). The email and email address are generated by formulae in spreadsheet cells. A script grabs the email and address from the spreadsheet and sends the email. Currently, the email is successfully triggered when the spreadsheet is manually edited but not via the IFTTT log entry.
Most of this project is achieved via formulae in the spreadsheet, rather than scripts, as I am much more confident using them.
The onEdit() trigger only fires on user input.
You should see if you can use onFormSubmit if IFTTT sends form-info?
My workable but untidy and unsatisfying solution is as follows.
The following functions are used to record the time and date that the Total Spent cell was updated.
function timestamp() {
var d = new Date()
return d.toLocaleTimeString();
}
function datestamp() {
return new Date()
}
SPLIT() and INT() are used to manipulate the date and timestamps into usable formats that can be compared with the current date and time. The datestamp() function always gives the date in PST so I've had to add the appropriate number of hours to convert it.
One IF() cell checks whether the date is today and another IF() cell checks whether the time has a value that is less than the time 5 minutes ago.
If the conditions are satisfied (total spent was edited today and less than 5min ago) the email cell is given the value of IFTTT's email address. If not the cell gets a space.
My sendEmails script is triggered every 5 minutes by an installable time based trigger. It will send an email to the valid address if the conditions are met and a blank email address if they are not.
One workaround could be the following:
You could make a script in this spreadsheet, and save the getLastRow() value in scriptproperties.
Compare them every minute or so via a timed trigger, and when it had increased, do your thing ;)
just change the trigger to be select event type to be "On Change". This will run the script whenever you edit it and also whenever IFTTT adds the row.

How can you generate a report for newly created groups/DLs on a weekly basis?

I am an admin for a Google Apps for Business domain and we want to be able to run a report to tell us what groups have been created in the last week. There is no such "Date Created" column for the groups. The best I have been able to do so far is run a list of the groups on a weekly basis but I want to be able to automate comparing that to the list from the week before.
You might as well store the list you have goten in a 'permanent storage' - a spreadsheet, ScriptDB or script Properties - and proceed to a comparison every week to see if something has been added (or removed)... This is maybe less straightforward and elegant but might be simpler to get working.
The weekly triggered function could do this :
get the list of names
sort it
write the sorted list to spreadsheet
retrieve the sorted list from last week by reading the preceding row in spreadsheet
compare both sorted lists at array level
and send yourself a mail with the difference.(eventually write the log to the spreadsheet)
This is certainly possible but requires a bit of coding.
You'll have to use the Audit API for this. See this response for some starter code on how to make basic calls to the API. The one tricky part is to set up OAuth 2 but its very possible after that.
Once you have the setup working you can then add additional startTime and endTime parameters to define your week interval along with the CREATE_GROUP event filter in the URL.