How can I get network days via Apps script? - google-apps-script

The reason why I need to do this on Apps Script is because I'm getting answers from a google form for a Time Off request tracker.
The Employee puts the start date and the end date for his request. On the spreadsheet I wanted to leave the formula: =NETWORKDAYS(D2, E2), but it doesn't work because when a new answer arrives the spreadsheet creates a new line which doesn't have the formula.
So I figure, since I'm using Apps Scripts to send emails with the Approval response, that there might be a way to use this "formula" or equivalent in the script and have the answer appear on the same row as the answer.
So leaving the formula on each row doesn't work, because when a new answer arrives, the spreadsheet creates a new line without the formula.

Related

Google Apps Script to add xlsx hyperlinked in gmail into Spreadsheet

I have a very specific task and I found many similar questions but they are all slightly different.
The script is triggered every day at 10am based of the top answer of this post: Is it possible to automate Google Spreadsheets Scripts (e.g. without an event to trigger them)?
I receive a report every day with lines that I want to add into the existing spreadsheet, so I get the report around 8am and then the attached data is added to the spreadsheet through the script.
The situation is that the email is an automated report from Amazon Display Advertising Analytics (Amazon DSP) and the xlsx file is hyperlined, not attached.
So the script, ideally gets the email list from my gmail account, searches for a specific email and retrieves a result. Gets the hyperlinked excel file and copies the content, except for row 1 which are the headers. Adds the content to an already existing spreadsheet.
In the end, I had the help of a Fiverr professional who scripted the code, so out of respect for him I won't publish his work, so if you are interested in it or if you need it, write me a private message!
In the end, I had the help of a Fiverr professional who scripted the code, so out of respect for him I won't publish his work, so if you are interested in it or if you need it, write me a private message!

How to protect the cell/range at the same time as appendrow

Im working on a website that stores data in a google spreadsheet and was wondering how I could use the appendrow() function and then protect that cell so no one can access it.
I'm new to google apps script and have been searching the internet for the last hour or so and can't find anything.
sheet.appendRow([text]);
But after that I would like it to get the value of that cell that was just written on so I could write:
var protection = the-row-just-written-on.protect()
I I am hoping for the result to be that no one can delete the text once it has been written on.

How is it possible to find the current row index when a google form is submitted/re-submitted? Google apps script

Is it possible to find out the current row index when a google form is submitted (or re-submitted using the Edit Response URL)?
I have been finding the last row number and then based on that an email is sent to the person who submitted the google form. This causes a problem when the same person edits his response at a later date and submits again, this leads to only the last row details being sent to the submitter - not his row.
I am aware of using the below functions:
e.values or e.range
I am just wondering if using them in google apps script, if its possible to find the current row?
Any help will be appreciated.
Have you tried:
e.range.getRow()

Auto create new sheet and email a summarized view of responses in google forms

I'm doing performance measurement for my office. And I probably just need to be pointed in the right direction. But here goes.
I want to make a form that employees can fill out every day, these responses go to a google spreadsheet.
I want this spreadsheet to create a new sheet for every week and then at the end of every month email the results to my boss.
What are my options for auto creating a new sheet, emailing results and summarizing?
Start by reviewing the Managing Responses for Google Forms quickstart. Then look at Installable Triggers, the SpreadsheetApp service and the FormApp service.
One strategy for what you need would be to have a script that (based on a weekly trigger), creates a new spreadsheet and then resets the Form's destination to that spreadsheet.
That script can also have another (monthly) trigger that uses MailApp to send a summary email to whomever you choose.

onEdit range always cell A1

I've run into an issue with the onEdit simple trigger using the [Google Apps Script] 3 in a Google Doc Spreadsheet.
The range in the event object passed to onEdit always maps back to cell A1.
There are a few other issues I'm encountering with onEdit and the event object but this is a very narrow and specific example which is hopefully easy to ask a question about.
My Repro Steps:
Login to google docs
Create new spreadsheet
Tools->Script Editor (this will open in a new tab)
Replace contents of Code.gs with the following (C&P from [https://developers.google.com/apps-script/understanding_events#eventsDetails])
function onEdit(e) {
e.range.setComment("Edited at: " + new Date().toTimeString());
}
Save changes to Code.gs
Return to the spreadsheet tab
Enter the number 7 into cell C3 then hit enter
Note: What's entered doesn't appear to matter, just need to trigger the onEdit event
Wait for spreadsheet to save change to server
Cell A1 is updated with a comment that says, Edited at: [current time]
The expected behavior is that the comment is added to cell C3. As per the [documentation stating] 2;
[The example in step 4] is a function that is triggered when a
Spreadsheet is edited. It uses the e parameter to access the cell that
was edited and add a timestamp.
Having this basic example from documentation failing leaves me at a loss of what I can be doing incorrectly or how else to approach finding a solution.
With the release of new sheets, a few of the Google Apps Script features where broken, in particular the one that you mention.
You will find documentation on this and other current issues here: https://developers.google.com/apps-script/migration/sheets#onedit_triggers
Be sure that the team is working hard to resolve this and you can probably have a shot as asking a question or two on the subject in wednesday Google Apps Unscripted : https://plus.google.com/u/0/116174873209306927411/posts/MbXQhKusUZ3?cfem=1