Stream

 
I am playing with tables in a document. First time working with the tables() class.I am going to try and copy data from a spreadsheet.

 Any suggestions?
1
Joris Steurs's profile photo
 
There might be something useful for you in this read https://plus.google.com/111703398740902944618/posts/7nBL9PTiv5q
Add a comment...
 
Using doGet/doPost in Apps Script as a data collection bridge to Google Sheets has been a popular post on my blog. My original solution didn't utilise features like ContentService and LockService so thought worth a revisit.

#gde #blogpost #googleappsscript  
Revisiting my POST/GET Google Apps Script example which lets you submit data to a Google Sheet (and other destinations) using your own forms or other ajax calls
11
10
Martin Hawksey's profile photoLionel Biennier Pers's profile photo
Add a comment...

Bruce Mcpherson
moderator

Tips & tricks  - 
 
 
The other day I showed an easy way to live with oAuth2 for Google API services from Google Apps Script. Using the same technique, accessing other oAuth2 services is a breeze. Here's an example of authenticating to soundcloud from GAS. #gde  
1
Admin FDCA's profile photoBruce Mcpherson's profile photo
5 comments
 
thx! ive seen some of those postings before on your site, helpful.  my other issues are also that calendar, shared contacts, gmail, etc all need to be fed/edited live so when I am mobile it's all there too. i'll poke around your site some more, but most of it is way above my head :-) thx again!
Add a comment...

Bruce Mcpherson
moderator

Tips & tricks  - 
 
Just came across this little trick.  You can find out which triggers exist for a project by using a URL like this - substituting the key from your project properties

https://script.google.com/a/macros/mcpher.com/triggers?lib=MO4jUsuvOVrUjzo7WPOICBai_d-phDA33
3
Bryan Patterson's profile photoBruce Mcpherson's profile photo
6 comments
 
had to save a version 1st for the url to work / create the lib. this still doesn't show me the triggers from every one else who's either the owner or an editor of the script, which I was hoping it would do. i've came into client projects before looking to get a quick glance at what was setup as a trigger if it wasn't documented / commented already. nice shortcut to your own though.
Add a comment...

Bruce Mcpherson
moderator

Tips & tricks  - 
 
Here's a library that orchestrates simple Map/Reduce functions to allow parallel processing of triggered scripts in Google Apps Script. Aside from doing multiple things at the same time also helps with the execution time quotas.

http://ramblings.mcpher.com/Home/excelquirks/parallel
#gde  
5
2
Martin Hawksey's profile photoLionel Biennier Pers's profile photoGAS LibraryApp's profile photo
2 comments
 
Magic! 
Add a comment...
 
Using Content Assist in Google Apps Script
#googledocs #googledrive
1
Add a comment...
 
Build your own digital downloads shop with #appsscript  
 
Sell digital products online with the help of Google Drive, Gmail and PayPal #howto
The guide explains how you can quickly and easily sell digital products like PDF ebooks, music, website themes, etc. through Google Drive, PayPal and Gmail.
5
1
John Holmes's profile photoOleg Moskalensky's profile photo
 
Great use of scripts!
Add a comment...
 
Saving Data Between Apps Script Runs via UserProperties
#googledocs #googledrive
2
Riël Notermans's profile photoMichael Ellis's profile photo
6 comments
 
Well yes, but the new proporties service is the problem... :)
Add a comment...
 
Connecting to MySQL Databases using Google Apps Script
#googledocs #googledrive
3
Michael Lynton's profile photo
 
This is exactly what I was looking for!!
Add a comment...

GAS LibraryApp

Tips & tricks  - 
 
Failure can be a lesson
If you miss goals, don't miss the lessons

We made a couple of mistakes during the last four years. Most of you will not understand the abstract insights but may be we can answer your questions in case you are curious. You will not need them in case you are not after an application and just automate a few tasks! And you should be familiar with inheritance also.

1. Libraries

One Library == One Class

You should not reuse a Class key as a Library key. Make sure to have your name space (object model) in place prior to implementation. The Class actually gets a different name e.g. Group.Index instead of GroupIndex. This will help you to combine the autocomplete feature of the built in IDE with classes and inheritance. e.g.

function get() {
    throw "Index.Id.prototype.get autocomplete function";
}

Index.prototype.get = 
  function () { ... }

2. Keys

You will need keys everywhere. For naming properties, addressing objects like spreadsheets, sites, etc. for some reason you need to be aware when a key actually is not longer a variable but a constant due to the semantic of the object, e.g. a site name can be a variable in your application but because urls are constants, you would get into trouble if you handle them the same way as you could handle spreadsheets.  

3. Scope

This was most difficult for us, because 1. leads to many libraries. But if you put many classes into one library, it is impossible to keep the overview if you do not just implement a task, unless you work with an external IDE i.e. not with Chromebooks. Our aim was to get rid of the overhead of a PC based development environment, if possible. And to be able to maintain the application everywhere with the least requirements for the device and we came close to it.

Make sure, the parent child relationships between your objects (classes) are generic. I.e. the less you apply inclusion to reuse or just use an implementation, the better! Because every time you update something, you might have to repeat consolidation (i.e. update versions manually) and that is an error prone procedure.

4. Hierarchy

Consolidation is impossible if you do not maintain a sorted list to track the hierarchy, i.e. which library includes another library. As soon as you detect loops, you are in trouble anyway.  Just a spreadsheet with columns: name, url, included, order - will help you to master this task.

5.  Documentation

Make sure to have the JS Docstyle documentation for the autocomplete functions as mentioned in 1. otherwise you will not benefit from autocomplete at all. When writing a function just omit "new" as long as necessary and type it in at last. Rather accept stumbling upon error than not having used the function correctly.

6. Testing

Test each function in isolation. Otherwise you will get stuck in debugging. The IDE debugger is good, but only as long as you stick to the basic concept behind Google Apps Script. 

We expect the Google Apps Development team to have realized the potential of their work and hopefully continue to grow. Google Apps Script is about to loose the advantage of having been "first" because developers have to follow the pack and the pack is going towards Office 365 at the moment, at least from our perspective. We would love to be proven wrong!

Google Apps Script is very unique and worth putting professional IDE behind that does not require these recommendations anymore.
4
1
Eamon Collins's profile photoGAS LibraryApp's profile photo
3 comments
Add a comment...
 
Documenting an Apps Script Library
#googledocs #googledrive
2
Add a comment...

Bruce Mcpherson
moderator

Tips & tricks  - 
 
 
In the past I've posted about how using libraries such as crossfilter can bring sophisticated wrangling capabilities to Google Apps Script. However, you can do some pretty complex data manipulation very easily in plain JavaScript. Here's a couple of examples #gde  
4
Michael Ellis's profile photo
 
WOW, there was a lot to learn in all of this.  Thanks +Bruce Mcpherson 
Add a comment...

Bruce Mcpherson
moderator

Tips & tricks  - 
 
 
#gde  I posted easy Ouath2 patterns for Apps Script for Google Datastore and soundcloud the other day. This one is for podio. Thanks to +Yuriy Klyuch for submitting. If you'd like to add any patterns, please let me know here or on my forum http://ramblings.mcpher.com/Home/excelquirks/forumgadget
1
Add a comment...
 
Create a Library in Google Apps Script
#googledocs #googledrive
6
2
István Maczkó's profile photoOleg Moskalensky's profile photo
Add a comment...

Bruce Mcpherson
moderator

Tips & tricks  - 
 
There's been a bit of discussion about easyCron on this community. I use GAS triggers for scheduling, but here is a library you can use from Google Apps Script to access the easyCron API if that's your thing. #gde  
1
1
Bruce Mcpherson's profile photo
Add a comment...
 
Breakpoints and the Google Apps Script Debugger
#googledocs #googledrive
3
Add a comment...

Set up Cron

Tips & tricks  - 
 
If your triggered scripts are accessible from web, you can try using online cron job service like https://www.easycron.com
4
Martin Hawksey's profile photoMichael Ellis's profile photo
2 comments
 
The benefit appears to be one for +Set up Cron ,
Add a comment...
 
here's something that might be useful - an experimental library with an implementation of named resource locking for Google Apps Script. #gde   #lockservice  
2
3
István Maczkó's profile photoBruce Mcpherson's profile photoGAS LibraryApp's profile photo
 
This will work for concurrent utilization of the same code, in order to sync interactive and automatic processes, e.g. when a user is working with a spreadsheet that is updated by scripts in parallel, one need to sync between two handlers via monitors. You can use this implementation to implement very robust mutual exclusive monitors.
Add a comment...

Joe Walder

Tips & tricks  - 
 
I worked on the Help Desk tutorial a while back and had something working. It wasn't complete and still had a lot of issues. The original code and instructions can be found here: https://developers.google.com/apps-script/articles/helpdesk_tutorial.

I finally had a chance to revisit the code and it seems to be working for me. 

Before you can start you will need to copy this form http://goo.gl/tuyunb and this sheet http://goo.gl/eusRw3 to your Drive. The sheet and form are not linked, so you will need to change the destination of the form responses to the sheet. 

In the sheet, open the form editor and copy in this script:  http://goo.gl/AF0LDA.

You will need to setup 2 triggers under the Resources menu: 
1. Run: onOpen, Event: From spreadsheet, On open
2. Run: formSubmitReply, Event: From spreadsheet, On form submit

You will need to make sure that the appointment calendar is setup to be public to your domain or the world to get the public cal id for line 194. You will also need to put in the email address at line 72.

If you follow sections 3 and 4 of the original post by Google, you can see how it all works. I left out the KB part since I didn’t need it. Let me know if you have any issues.
1
Add a comment...
 
Autocomplete for own Classes in IDE
a detail that matters, but there might be an alternative!

If you were interested in the previous post: https://plus.google.com/104403800912062884925/posts/D5xpGd817fE

and already have experience with the subject, you have noticed that there was a special case used as an example. In the special case we assume a separate API library is included. In the example we recommend to integrate global functions directly into the class library that throw an error in case they are called.

In order to lookup the interface, one has to type in "Dot" if thats the name of the library. In the screenshot attached to this post the name of the class is "Mail". In order to lookup the interface of Mail, just type in Dot. and the autocomplete feature will present a list of possible functions. 

Get "getPrivateFunctions" is a meta function, as well as "getLibrary()" so we are sort of "breaking the rules" in order to implement generic functions, it does not take that much time to learn the keys of the generic functions. 

We wonder if there might be a better way for library management, that allows us to implement our own service classes. We assume that this is not possible because there are so many different implementation styles for Java Script. 

We thought of making our way a recommendation for best practise but hesitate because of the overhead.  Compared with the behaviour of the Google Apps Script service classes you will notice the difference.

The constructor of Google Apps Script service classes encapsulates "new".

var x = SpreadsheetApp.getActiveSpreadsheet();
x. will list the API of "Spreadsheet"

And the difference is, you do not have to include "SpreadsheetApp" in order to use the interface of "Spreadsheet", it is part of the IDE's autocomplete "knowledge".  

How could we achieve the same with our own "Mail" class as the Google Apps Script team achieves with the "Spreadsheet" class?

If you would know the answer, please share it with the community.

Providing the solution supports inheritance!
1
GAS LibraryApp's profile photo
 
Just to complete our experience: It is more work but the better trade off if API library for autocomplete functions and Class Library are separated. At first we thought we were better of with one class == one library. But after going through all the trouble of reorganizing the source code we must admit, that sometimes we have separated classes, that should have stayed in the same library for good reason. 

The criteria to balance are:

1. Inclusion hierarchy of the libraries matches inheritance and in some cases aggregation relationships. Consolidating a version for publishing benefits from lesser libraries.

2. But in order to role back in case of unexpected failure, one is better of with one library == one class. With GAS Library App we can track all changes (more or less, we will update the implementation that diff will be better in the future). So in case it is needed, to return to a previous version will be easier.

3. Scope is not a hurdle, if you know how to circumvent it, but it is dangerous and not part of the library concept. So if you use our meta function getLibrary for one library, you can use it for all libraries. As is needed for GAS Library App anyhow, we had to let go the benefit, that a library could have private functions and attributes. 

If you would not apply prototype declaration, you could of course integrate API and Class library!

function class () {
    this.apifunction = apifunction;
}

function apifunction () { ... } 

We hope some of you might have found a better solution and are looking forward to your experience.
Add a comment...