{"id":751,"date":"2011-10-01T12:02:10","date_gmt":"2011-10-01T18:02:10","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=751"},"modified":"2011-10-01T02:21:52","modified_gmt":"2011-10-01T08:21:52","slug":"running-a-google-apps-script-once-a-month","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/751","title":{"rendered":"Running a Google Apps Script Once a Month"},"content":{"rendered":"<p>I needed a way to email a Google spreadsheet to my boss once a month, for some reporting purposes.\u00a0 I could have put an entry in my calendar reminding me to do it, but I thought it would be a great time to try out the <a href=\"http:\/\/code.google.com\/googleapps\/appsscript\/\">Google Docs scripting<\/a> that I had read about for a year or two, and seen an <a href=\"http:\/\/www.appsumo.com\/google-docs-unleashed\/\">AppSumo video<\/a> about.\u00a0 (I got the AppSumo video for free, from an ad on <a href=\"http:\/\/www.helpareporter.com\/\">HARO<\/a>.)<\/p>\n<p>It was laughably easy to get write the actual script (here&#8217;s a <a href=\"http:\/\/code.google.com\/googleapps\/appsscript\/articles.html\">great set of tutorials<\/a>).\u00a0 The only rub was Google doesn&#8217;t allow you to run scripts in month intervals, only hourly, daily or weekly.\u00a0 A small bit of scripting got around that.<\/p>\n<p>Here&#8217;s the final script (edited to remove sensitive data):<\/p>\n<pre>function myFunction() {\r\n  var dayOfMonth = Utilities.formatDate(new Date(), \"GMT\", \"dd\");\r\n  if (dayOfMonth == 05){\r\n    MailApp.sendEmail(\"email@example.com\", \"Spreadsheet Report Subject\", \r\n'https:\/\/spreadsheets.google.com\/a\/mydomain.com\/ccc?key='+SpreadsheetApp.getActiveSpreadsheet().getId());\r\n  }\r\n}<\/pre>\n<p>I set up a <a href=\"http:\/\/code.google.com\/googleapps\/appsscript\/guide_events.html\">daily trigger<\/a> for this script and installed it within the spreadsheet I needed to send.<\/p>\n<p>I really really like Google Apps Script.\u00a0 I think it has the power to be the VB of the web, in the way that VB made it easy to automate MS Office, reduce drudgery, and allow non developers to build business solutions.\u00a0 It also ties together some really powerful tools&#8211;check out <a href=\"http:\/\/code.google.com\/googleapps\/appsscript\/defaultservices.html\">all the APIs<\/a> you can access.<\/p>\n<p>Once you let non developers develop, which is what Google Apps Script does, you do run into some maintenance issues (versioning, sharing the code, testing), but the same is true with Excel Macros, and solving those issues is for greater minds than mine.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I needed a way to email a Google spreadsheet to my boss once a month, for some reporting purposes.\u00a0 I could have put an entry in my calendar reminding me [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,39,10,53,33],"tags":[],"class_list":["post-751","post","type-post","status-publish","format-standard","hentry","category-business","category-cloud-computing","category-dynamic-languages","category-google-apps","category-useful-tools"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=751"}],"version-history":[{"count":5,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/751\/revisions"}],"predecessor-version":[{"id":756,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/751\/revisions\/756"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}