Showing posts with label Google Apps Script programming. Show all posts
Showing posts with label Google Apps Script programming. Show all posts

Tuesday, June 12, 2012

Google Apps Script: How to retrieve more than 200 items from a List Page


We're constantly building customer solutions for Google Apps, Solve360, Freshbooks, and Xero with Google Apps Script and Google App Engine.   Below is a handy tip for Google Apps Script developers.

Google Apps Script
Posted on behalf of Cameron Roberts, Senior Developer, Interlockit.com

When interacting with a Google Sites list page via the Google Apps Script SitesApp service, the documented getListItems() function returns only 200 items, while the maximum length of a List Page in sites is 500 Items. This function takes advantage of undocumented parameter values that can be passed to getListItems() to retrieve all items in batches of 200.  

/*
   Function: getAllListPageItems(page)
  Parameter: page - An instance of the Google Apps Script Services "ListPage" class.
Description: A robust function which uses undocumented Google Services functonality to retrieve ALL items from a list page. At time of writing (June 2012), the Google Services getListItems() method returns only the first 200 items of a ListPage. This function will catch failed API calls and re-try until all list items have been retrieved. This function will also throw an informative exception if the passed parameter is not a valid ListPage object.

Usage Example:
 
   //retrieve items from list page and write to Log.

   var page = SitesApp.getPageByUrl('http://sites.google.com/a/yourdomain.xyz/yoursite/yourListPage');
   var items = getAllListItems(page);

   for(var i in items){
       var item = items[i];
       Logger.log(item);
       //..Perform your processing on list items here.
   }


Written by Cameron Roberts, Interlockit.com

*/

function getAllListPageItems(page){
  if(page && page.getPageType && page.getPageType() == 'ListPage'){
    var items = [];
    var start = 0;
    var size = 200;
    var failed = false;
    do{
      try{
        var item_batch = page.getListItems({start:start,max:size});
        failed = false;
        items = items.concat(item_batch);
        start += size;
      }catch(e){
        failed = true;
      }
    }while(item_batch.length == size || failed);
    return items;
  }else{
    throw 'Parameter passed to getAllListItems was not a List Page: '+page;
  }
}



The relevant post from Google, which exposes the undocumented functionality, is http://code.google.com/p/google-apps-script-issues/issues/detail?id=666

Tuesday, February 14, 2012

Interlockit.com Becomes a Google Apps Premier SMB Reseller

Interlockit.com announced today that it has become a Premier SMB Reseller of the Google Apps™ suite of communication and collaboration tools. This new designation from Google enables customers to more easily assess a reseller’s expertise advising on and deploying Google products. Interlockit.com has moved from an Authorized to a Premier Reseller based on their expertise and success in helping customers deploy and use Google Apps.


Interlockit.com was launched in 2009 to help small and medium businesses (SMB's) leverage Google Apps for an enterprise class email, calendar, and document collaboration solution that's easy on the wallet, simple to use, and allows you to be productive from anywhere, with anyone. Our solution offering has grown to include Google Apps integrated products such as Norada Solve360 CRM/project management, Freshbooks billing, Xero accounting, plus custom programming on Google App Engine and Google Apps Script.

Google Apps brings simple, powerful communication and collaboration tools to organizations of any size – all hosted by Google to streamline setup, minimize maintenance, and reduce IT costs. With Gmail (including Google email security, powered by Postini), Google Calendar, and integrated IM, users can stay connected and work together with ease. And, using Google Docs and Google Sites, which include word processing, spreadsheet, presentation and website creation tools, they can share files and collaborate in real-time, keeping versions organized and available wherever and whenever users work.

The Google Apps Reseller program includes companies globally that sell, service and customize Google Apps for Business for their customers. As a part of the Apps Reseller program, Interlockit.com receives training, support and deployment tools from Google, as well as access to APIs for integrating Google Apps into their customers' business operations. To learn more about becoming a Premier Reseller, including eligibility criteria and benefits, please visit the Google Reseller Program website: http://www.google.com/enterprise/resellers.