Accessing event attachment via Google Apps Script - google-apps-script

Is it possible to get at calendar event attachments within google apps scripts? I realize that this is still a "google labs"-level feature, but getAttachments() would be really handy for some stuff I'm working on. Failing that, does the lab store its attachment data in a clever location (say, a tag containing a URL) that I could get at behind the scenes?

Not possible as far as I know. As you've mentioned, it is a Calendar Labs feature. Many regular features are not available in Apps Script, so it is tough to expect this one. You can try opening a feature request though

Related

Get the email address of a "people chip"?

Does anyone know if there is a way to use the Google Sheets API to get the email address of a people chip? It seems like the only values it will give me are the person's full name as displayed in the cell.
While trying to figure this out I discovered that the name turns into an email address if you use "Format > Clear Formatting". I hoped I could hack this by copying the value into a hidden sheet, clearing the formatting, and then get the email address there. But though Google Apps Script has a function for executing that on a cell, I have found no way to do it with the Sheets API. I tried clearing all the possible formats I could via batchUpdate with an updateCellsRequest but that isn't turning the people chip into an email address.
I'm at the point where if I really want to automate this, I will need to use the scripts API as well, to deploy and execute a tiny Apps Script just to run clearFormat on a cell. I'd like to avoid this much complication, especially since Apps Script doesn't work for service accounts.
As Tanaike mentioned this is not possible at the moment but there is already a feature request in the Google Issue tracker related to adding the people chips to the Sheets API. You can check the request here.
I would suggest posting a comment on it and explain why you are interested in this feature. Or if you think your request has a different approach you can also submit a new feature request for the Sheets API here.

How can I Find All Uses of a Google Script Library?

I have a Google Script library that is used by at least 100 other scripts (some that are bound to spreadsheets/documents, some that are not). How can I find all of these client scripts that reference my library script?
More specifically, I need to be able to add a new feature into the library that requires new permissions that I (the user) must grant. The client scripts won't run if I just add this feature to the library without granting the permissions to each of the client scripts. So ultimately, I need to give this new permission to each of the clients. And if I knew what scripts were actually using this library, I could do that manually for each one. But I need to URL's or ID's or something for each of those scripts.
Answer:
Unfortunately this is not possible to do.
More Information
It is possible to get a list of standalone Scripts from your Drive, though scripts bound to a file can not be searched for using regular searching methods.
It is possible, using the help of this Google Account page to get a list of all the Apps that have access to your account, though only files you have authorised will appear here, and apps which are not just those created by you in Apps Script will appear there (for example, other add-ons or even Android Apps bound to your account appear here).
A Partial Workaround:
Using Google Apps Script, you can list all Apps Script Projects that you own with help of the MimeType enumeration GOOGLE_APPS_SCRIPT
var scripts = DriveApp.getFilesByType(MimeType.GOOGLE_APPS_SCRIPT);
var arr =[ ];
while (scripts.hasNext()) {
var script = scripts.next();
arr.push(script)
}
Logger.log(arr);
Or even just searching for type:script in Drive, however this only returns a list of scripts that are not bound to a file.
You can then use regular Google Drive search terms to find which of these files contain, for example, a unique method name that the library uses. I am aware this isn't a perfect solution and you would still have to look for projects bound to a file using the above webpage.
Feature Request:
It appears that back in 2014 a feature request for this was made on Google's Issue Tracker, though I would suggest creating another feature request for this here as it was marked as a duplicate of another issue. You can make a feature request under the correct Apps Script component here.
References:
Google Apps Script - Enum MimeType
Google Drive Search Query Terms
Apps with access to your account
Google's Issue Tracker
Feature Request: Listing and searching for container bound scripts
Create an Apps Script Feature Request

HTMLService or Google Apps script

I've use Google Apps Script before, but haven't bene programming for oabout a year now.
For a new project I would like to know if I should continue using Google Apps script or switch to HTMLService.
So first question is if Google Apps Script still is and well be supported by Google.
Second question is what are the main differences between HTMLService and Google Apps Script that make it worth switching.
If you mean should you use HTMLService or UIService within Google Apps Script, it would probably be best to use HTMLService as UIService is deprecated.
UIService will appear in auto-complete until 30th June, but not after.
https://developers.google.com/apps-script/sunset?utm_campaign=htmlser-1214&utm_source=gadbc&utm_medium=blog
http://googleappsdeveloper.blogspot.co.uk/2014/12/speeding-up-htmlservice.html
https://developers.google.com/apps-script/guides/html/
For first Question: Yes, The Google app script used to make google products as custom like google spread sheet , google docs and we can insert the script into google sites so that we can share output through website.
For second Question: In Google app script the ClassUIApp is deprecated in that place we can using HTML services
https://developers.google.com/apps-script/reference/ui/ui-app
In the beginning Google App Script, all the code was written in one file one with .gs extension which included the code for User Interface, styling and business logic which made it complex as the application moved from small scale to enterprise level.
Also there was a restriction that you have to use the UI components from App Script (UiApp) which was not welcomed by the existing community of web developers as it was limited and needed to be learned and could not offer all the features a programmer may require.
Therefore in order to make it popular among existing community of developers App Script gave the ability of writing HTML pages as part of the project which was very helpful as it is widely used for designing all kinds of UI.
So, as you can see here that Google has made a shift, and hence HTMLservice is the future.
Google Apps Script was design for interact with google apps, so, if you are working with google drive, calendar, maps. You must use apps script, It's is easy and fast to implement.
But if you don't need use Google Apps may be is better use another software because how I told you before, Apps Script was created for interact with Google Apps and works awesome.
Google say: "The HTML service lets you serve web pages that can interact with server-side Apps Script functions. It is particularly useful for building web apps or adding custom user interfaces in Google Docs, Sheets, and Forms. You can even use it to generate the body of an email."
https://developers.google.com/apps-script/guides/html/
The purpose is different, what do you want to do?
Been following updates from Google in regard to GAS for over 6 months now. Google is putting a lot of resource into GAS and I don't think there should be any concern about it being deprecated.
And HTMLService is a class that can be called from inside the script editor so I don't know why one would need to choose one or the other.
Just go into the script editor and press control + space bar at the same time and you'll see all the classes available to you in alphabetical order. Scroll down to H and you'll see HTMLService. I haven't used it yet but it's there to work with.
HTMLService is a service to serve HTML pages through Google Apps Script. You can use HtmlService as a normal web page.

How to build a decision support app with Google Apps Script (forms with subquestions)?

I want to create an app which helps newbie employers to take some simple decisions. So, using their answers to a form, the app asks new questions based on previous responses, something similar to a decision tree. Is Google Form a good alternative to implement this? (something like this suggested here, but with more questions:
Are there alternatives based on Google Apps Script?
What you need is a Google Form with a lot of questions, whose answers redirect to different pages in the Form.
You can also use Google Apps Script Forms Service to create Forms through code (and you can use previous responses in old Forms to generate new content for new Forms dynamically).
A typical example of this would be:
Create a Google Form with several questions with redirects based on answers (decision trees).
Have the responses to that form go to a response Spreadsheet.
Run a script on the response Spreadsheet to generate new content using the Forms Service within Google Apps Script (or do this manually; both work).
Send out the new Form to employees by email (you can use Gmail Service to accomplish this) or however you prefer.
--> and repeat the process as needed.
At my work, I use Google Forms with redirects and scripts on the response Spreadsheets in order to process faculty requests using Google Apps Script, so this is definitely possible!
However, it should be noted that Google Apps Script cannot be used to dynamically generate content for Forms while the user is filling it out. See my question here.
I don't feel like typing a mass of code here, but there are two ways of accomplishing this (both of which would require a lot of script code):
You could potentially accomplish this by making a web app that automatically dumps the responses into a spreadsheet (limited space) or a document (which doesn't have to be human-readable). This won't give you the same UI, but it would work, assuming you are familiar with making web apps in the first place.
You could make a multi-page form that you could write some code to direct the person upon selection of whatever choice they make to go to the correct page. This other question may serve of use if you want to go this route (it likely will be a bit easier).

How can I add a Google apps script to a spreadsheet created using the API?

After reading up a lot on the Google Spreadsheet API I have come to the conclusion that formatting (such as merging cells, changing fonts etc) is only available throught the Apps scripts.
Since we need to create and fill the spreadsheets with data programatically using Java on the back-end I guess I need to somehow either;
link the new sheet to a Apps script that trigger on-load or
create a Apps script that creates the spreadsheet for me.
Anyone knows?
If you want to just "create" the spreadsheet, you don't need a script to load whenever it spreadsheet is opened. It's probably easier to develop a script that runs once and create the spreadsheet for you.
Another tip is to have a template file that you can copy with most of the formatting (if not all) already there. Possibly pending just little things that are related to the real data the new spreadsheet will have.
Edit to answer the question in the title.
No, you can not add a script to an existing spreadsheet programatically, only manually. What you can do is previously set up a template spreadsheet with a script in it and create new spreadsheets by copying this template.
(answering the comment)
You can run a script programatically, but not upload it. To run a script you can deploy it as a web-app and call its url with either a http get or post (will call its doGet or doPost functions, that you must have declared). Also, you could set this script to run on form submit of any spreadsheet-form and just submit a set of answers to this form. At last (that I can think of now) you could just add the script as a library in another Apps Script and call it directly.
(Aug 2016) There is no way programmatic way to link a Google Sheet and Apps Script code other than manually. Based on what it seems you want ("create and fill the spreadsheets with data programatically using Java"), you can now do it without Apps Script.
TL;DR: Above, #Henrique has answered multiple questions and even questions that weren't asked! The good news is that today, we have more answers representing alternate possible solutions to what you're seeking.
It's now possible to "upload" Apps Script code programmatically with the
import/export system, say with Eclipse since you're a Java developer (2013 announcement).
I agree with Henrique's suggestion that if you create a spreadsheet
template, i.e., Excel file, you can use the Google Drive API to
programmatically import/create identical Google Sheets with all your
desired formatting.
"Formatting (such as merging cells, changing
fonts etc)" can now be done outside of Apps Script, as there is a
"new" Google Sheets API v4 (not GData).
In order to use the new API, you need to get the Google APIs Client Library for Java and use the latest Sheets API, which is much more powerful and flexible than any previous API. Here's one code sample to help get you started. If you're not "allergic" to Python, I also made a video with a different, slightly longer example introducing the new API and gave a deeper dive into its code via a blogpost that you can learn from.
Note the v4 API allows you to create spreadsheets & sheets, upload & download data, as well as, in the general sense, programmatically access a Sheet as if you were using the user interface (create frozen rows, perform cell formatting, resizing rows/columns, adding pivot tables, creating charts, etc.), but to perform file-level access such as uploads & downloads, imports & exports (same as uploads & downloads but conversion to/from Google Apps formats), you would use the Drive API instead.