Google Apps Script to add xlsx hyperlinked in gmail into Spreadsheet - google-apps-script

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!

Related

Is there a way to have a Google Form response trigger the creation of a new Google Sheet?

I do not have any experience with apps script. Something I am trying to learn currently and this is my first project that I will be working towards.
My company that I work for use a mundane spreadsheet which is used as our purchase document. I have translated it to a Google Sheet that looks like this: https://docs.google.com/spreadsheets/d/1mZlzeu9-9Mb0B1VmlNSJDfCxELqci4KRc_HFbRt3NwM/edit?usp=sharing
Currently, anyone that makes a purchase needs to fill out this spreadsheet and send along a copy of the receipt of the purchase via email to our billing person.
The Google Form I want to create to streamline this will contain basic information like the name of the person filling it out and an email address. I would add some of the items below along with a Google Drive Upload so that the person can upload a picture of the receipt(s).
What I would want to have happen is on a Google Form response, I would like apps script to do the following, in this order:
Create a copy of the spreadsheet linked above and Title it as "[Team Name] [Date] Credit Card Request"
Fill it with the information that is needed:
Date of Transaction
Amount Request
Vendor Name
Program Name (I think this can be done away with because of Team)
Team
When the spreadsheet is filled out, I would like to then email the billing person a completed XLSX copy along with the file attachments that were uploaded for that response.
3a. Sending a copy of the same email to the person filling out the form originally would be a plus.
Because of the format of this spreadsheet, when the team is specified, I am hoping I can have the Apps Script set the value of the corresponding cell for that team (a checkbox) to TRUE.
I may ask for some assistance with this later on, but I am wondering, **is this possible to do? **
My apologies, I do not have any script experience, not sure where to even start.

Best way to share inside my domain a script embedded in a spreadsheet

I have a spreadsheet, with 2 scripts embedded, that monthly is sent to some accounts (teachers) inside my domain. One script reads a form (exam) and write the results in the spreadsheet, the second script transfer the final evaluation (the teacher must add other info to the exam scores) to another public spreadsheet where the people can see the results.
Everything works fine, except that the first run of one of the scripts, asks for Authorization. I'd like to avoid that and I read many articles about Authorize scripts, but I couldn't find the solution.
I don't need to Publish an App, that is far away from my needs and my abilities.
I explored Add-on feature, but in some forums I read that there are limits for the Add-on capabilities and possibly it doesn't work between forms and spreadsheets.
So, is there any option to distribute a script inside my domain and the people are not required to Authorize it?
You can add an installable onEdit trigger from your account, trigger script function if specific cell is updated by the rest of the user.

Google Admin Directory SDK Users.list() Returning Old, Not Current, Data

I am working on a project for my company, that well is kind of complicated. I am not sure if I will be able to explain it as well as I need to.
Basically, this is how it works:
A user fills out a Google Form that represents a user in our company, either new or existing
My Google Apps Script gets the last form response, triggered on form submission
That script then relays that last form response data to the custom schema fields I set up on Google Admin
Once the user is updated, I grab ALL the users in the domain and paste them into a google sheet
The spreadsheet represents our company roster. We originally just tried to maintain the data solely in a spreadsheet, but it became a mess.
To solve this, we introduced the google form, which can validate all data. Furthermore, our data is backed up to Google Admin (within custom schema). The spreadsheet is solely for display. It is bulletproof. Upon refresh, it pulls the data, and re-writes the sheet.
However...
I am noticing that after the form is submitted and the user is updated in Google Admin, and then all the users are pulled from Google Admin, the user that was updated isn't showing as updated in the spreadsheet. However, if I refresh the page, then the correct data shows up (I have another script that triggers on spreadsheet open, literally the SAME EXACT code that runs after the form submission). Why does that code return the proper data on refresh, but not when run directly after the form submission and consequent user update in Google Admin?
I really am dumbfounded and having an incredibly hard time explaining this because it does not make any sense. My boss and I both spent the entire day scratching our heads on this yesterday.
Do you guys have ANY ideas?
Is there a cached response, possibly accounting for the non-current data from Google Admin?
When I used the Admin Directory SDK API Explorer, the user modified shows as current. I just don't seem to be getting that same response when my script runs.
I am so lost. I spent 2 months developing this system. It worked in development.
Any and all suggestions are appreciated

Turn OFF “Authorization is required” for Google Sheets Script for own team

We are a small company which just switched from paper to tablets (Surface GO Win10 Home) and we have one particular sheet which is used for every order (about 100 orders per month). This Google Sheet acts as a template for every single order and includes some easy code which is written in a bound Apps Script project, to handle things like switching the status from started to finished, copying some cells etc.
My problem is, when someone of the team wants to use the created "buttons" in the sheet to activate the script, it asks for authorization for the script the change the sheet. If you enable it, everything works fine but then for every new order you have to enable it again, and again, and it gets really annoying for every team member.
I tried somehow to
turn it off in the security options as administrator
tried it in the GOOGLE CLOUD PLATFORM under API's and services
tried to make the code somehow public in the script editor options
...but nothing seems not to work. I used VBA programs a lot in Excel VBA but it was more a hobby and I'm not a computer scientist, otherwise it would maybe be easier to solve this problem.
Is there an easy way so every one of my team can work with the sheets created out of a template without any request from Google for authorization every time.
Kind regards.
The reason for the popups is that Google Apps Script is not part of Google Sheets itself, it's a separate application that uses OAuth 2.0 to get the permissions to make the requests by calling the APIs. The popup shows the scopes you are authorizing for. This means that you can't disable that.
Note that apps script could do more things that just edit the spreadsheet itself; it could get other files, get your personal information, call external servers, etc. Also, the authentication process will only happen once per file.

Pulling data from Sheets into Gmail template - one email at a time, not a bulk mail merge

I'm trying to come up with a solution that will allow me to (1) pull data from Sheets for only ONE of the rows into a Gmail template and (2) allow for modifying the template with additional information that's not in the spreadsheet before sending it off.
Context: My organization uses an intake/referral log to track key information about referrals. Once info is in the Sheet, they manually send an email assigning the referral to an employee for follow-up. Much of the info in the Sheet is retyped...which initially made me think of automating this fully with AppsScript, so that all the standard info (case #, case type, due dates, etc) is included in that email. However, the emails sometimes have a paragraph or three of contextual information that we don't want to store in the spreadsheets and have pulled into the automated email.
So my goal is to pull the data from the spreadsheet into the email where I can (vs having to retype it) AND allow the addition of contextual info before sending it off to the assigned employee.
Any thoughts on how to accomplish this? I haven't found a mail merge add-on or Apps Script solution that allows doing this one row at a time and adding in extra custom info into the email.
Thanks in advance!
So this question, as currently written, could clearly be accomplished a whole bunch of different ways. With that in mind, here is one quick and dirty way in which it might be accomplished:
On the spreadsheet where the data is stored, create a script via tools>script editor.
Using that script, create a menu which runs a function that does the following, perhaps in an endless loop:
a. Prompt the user for the email address of where to send the email if it isn't in the spreadsheet or a token value, such as an empty string, to end the script.
b. Prompt the user for the number of the row where the info is stored.
c. Prompt the user for any extra contextual information to add to the email.
d. Get the info from the applicable row in the spreadsheet.
e. Create a nicely formatted email and send it off.
From there, the person in charge of doing the referrals would simply run the script and feed it the required information. Clearly human error could fowl things up here, but without more details of exactly how you want this to work, it isn't really possible to define exactly how to best protect against human error. Reading up on Data Validation might give you a start on that front.
And if you are still completely lost, I happen to be a Google Apps Script tutor/consultant who often gives away free tutoring/consulting. See tutoringbyroger.com for more on that.
I hope that helps.