text:
Q: Google Apps Script document not accessible by replaceText() Here is my code and I can't figure out why replaceText() isn't working.
function createDoc(){
  var templateid = "1jM-6Qvy47gQ45u88WfDU_RvfuSTsw27zBP_9MfsUGr8"; // get template file id
  var FOLDER_NAME = "Completed Rental Agreements"; // folder name of where to put doc
// get the data from an individual user
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var data = sheet.getRange(2, 1, sheet.getLastRow()-1,sheet.getLastColumn()).getValues();
  var lastRow = sheet.getLastRow();

  var firstName = sheet.getRange(lastRow, 2, 1,1).getValues();
  var lastName = sheet.getRange(lastRow, 3, 1,1).getValues();
  var guestEmail = sheet.getRange(lastRow, 7, 1,1).getValues();
  var companyEmail = "bearlakeprojectmanagement@yahoo.com";
  var companyName = "Bear Lake Project Management";
  var username = "jared.hislop.test@gmail.com"; // get their email (from sheet name)
  var me = "jared.hislop.test@gmail.com";

  //Copy Template
  var docid = DocsList.getFileById(templateid).makeCopy("Rental Agreement - "+firstName+""+lastName+"-"+guestEmail).getId();
//  var file = DocsList.getFileById(docid).addEditors(me);

 // move file to right folder
  var file = DocsList.getFileById(docid);
  var folder = DocsList.getFolder(FOLDER_NAME);
  file.addToFolder(folder);

  var doc = DocumentApp.openById(docid);
  var body = doc.getActiveSection();
  var body_text = doc.addEditor("jared.hislop.test@gmail.com");

 //  Append Cabin Rules
//   doc.appendParagraph("This is a typical paragraph.");
body.replaceText("/^companyEmail$/", "test");
body.replaceText("%companyName%", "test1");
body.replaceText("%todayDate%", "test1");
doc.saveAndClose();

}
I've tried doc.replaceText and body.replaceText along with several other options.
Any ideas why this isn't working?
Thank in advance

A: Consider this:
body.replaceText("%companyName%", "test1");

That will look for every instance of "companyName" with "%" on either side of it. The "%" in this case is just that, a piece of punctuation in a strange place. This is a convention used to decrease the likelihood of accidentally replacing real text in the document.
Your template document must have that exact pattern for the replacement to work. (Yours doesn't... instead you have just "companyName". Change it to "%companyName%".) Apply that rule for any other replacement you want to make.

You could benefit from some optimization.
  ...
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  // Next line is hard to maintain - there's a better way.
  // var data = sheet.getRange(2, 1, sheet.getLastRow()-1,sheet.getLastColumn()).getValues();
  // Read whole spreadsheet, skip headers
  var data = sheet.getDataRange().getValues().slice(1);

  // Already read in all data, use it instead of reading sheet again.
  var firstName = data[data.length-1][2-1];    // (2-1) because array counts from 0
  var lastName = data[data.length-1][3-1];     // while spreadsheet columns from 1
  var guestEmail = data[data.length-1][7-1];   // Better: put these into variables.
  ...

While experimenting with your code, I ran into an autocompletion issue with doc.getActiveSection(). It turns out that there has been a recent change, according to the release notes for April 15 2013.

Renamed Document.getActiveSection() to getBody().

You should update your code accordingly.

redpajama_set_name: RedPajamaStackExchange


The IDE world just started to look a little greener for Griffon programmers. Today's latest early access version of JetBrains IntelliJ version Maia has initial support for Griffon!
It appeared on the JetBrains blogroll a couple of weeks ago, and indeed may have showed up in an earlier release, but today was the first time I saw it in action. I couldn't find anything about this new feature mentioned explicitly in the release notes but sure enough, it's there. Given the similar project structure between Grails and Griffon, and the first class Grails support already available in IntelliJ, it's really not too hard to see how this platform is in an ideal position to expand Griffon support. Beyond that the general Groovy support seems to get better in every release. The EAP is free to try for any holder of an IntelliJ 8.x license and seems to be pretty stable despite the disclaimers – I highly recommend taking it for a spin, especially if you're already using this IDE. You get properly configured source directories and dependency paths, access to Griffon's command line scripts, and even that awesome new Griffon icon shown to mark out the project. What more could you ask for?
JetBrains was beaten to the punch by a NetBeans plugin for Griffon that was released in its initial version before this year's Java One conference. I'm not a NetBeans user myself, but I am a frequent reader of Geertjan Wielenga's blog – he's published some great Groovy examples. Even the Eclipse community has finally gotten around to putting out some real Groovy support, largely due to SpringSource's commitment.
Regardless of which development environment you feel most comfortable with, there's no questioning this is a great time to be a Groovy/Grails/Griffon developer so enjoy!


We took about 35 minutes to travel from Bidor to Teluk Intan. Once we reached the town, formerly known as Teluk Anson, at about 1.30pm, the first thing we looked for was its most famous landmark: Leaning Tower of Teluk Intan. As it is located in a square, you won't miss it as its top is obviously seen among low-rise buildings from a distance.
At this hour, the weather was very hot and we took a quick tour of the Teluk Intan clock tower – which was built in 1885. We were only allowed to climb up to three floors.
Since we had not had our lunch, we were looking for a place to fill up our stomachs. We wanted to try the well-know Teluk Intan chee cheong fun. But unfortunately, based on my research notes, the famous Teluk Intan chee cheong fun is only available in the evening. It was then confirmed by a local shop assistant near the clock tower. To make it worse, it seemed that our chances were slim to get a proper lunch at this time of the day.
Another agenda on my list was looking for the popular heong peah cap harimau (Tiger Head brand biscuits). The shop assistant explained to me how to get to the biscuits shop which was not very far from the clock tower. It is actually located at the end of the road.
After buying some biscuits for own consumption and as gifts for friends, we continued our search for food. While we were touring around the town aimlessly, I saw the popular Ah Chai Rojak Stall as mentioned by one Teluk Intan blogger. It is located behind San Min School and next to the wet market. The rojak stall is a modest stall with some wooden shacks. If you are not careful, you will miss it. When we were there, there were only a handful of customers there.
Since we had no other food, we took rojak (mixed fruits in dark sticky prawn paste) for lunch though it was usually meant for snack. I find the rojak okay and not as good as what I expected. I prefer rojak with a stronger taste.
K didn't find the rojak appetizing and we had to get something for him before he threw tantrum, we quickly headed to Teluk Intan's Glutton Square for some hawker food. Not many stalls were open then. By accident (I saw a lady carrying some yu tiao) I found a stall selling yu tiao and ham chin peng – also in Glutton Square.
Note: This is the third article of Family Weekend Getaway: A Road Trip To Lumut series.


Despite what some people believe, roofing is a year round trade. Customers often ask us if roofing can be done in the winter. Sometimes it absolutely should be done in the winter, but it truly depends.
Roof work can be split into two major categories, roof repairs and roof replacements.
Just about any roof repair can and should be done year round. In warmer weather, shingles self-adhere. If it is too cold for there to be an immediate seal, caulking is used instead.
IF YOU SKIP YOUR ROOF REPAIRS DURING THE WINTER AND YOU HAVE BROKEN OR MISSING SHINGLES, YOUR SMALL REPAIR WILL BECOME A LARGE ONE!!
If snow piles on the roof and your shingles are broken or missing large quantities of water will seep in and ruin drywall and other parts of your home. If left alone for the entire winter you could be facing more expensive repairs.
Snow can be a more serious threat than rain for a roof structure that's not intact. That's because the snow that is closest to the roof melts before the snow above it and water has more of a chance to meander into the roofing system.
If your roof is in need of repair and snow season is upon us, it's time to act. Our roofers are busy at work repairing roofs during the winter season for this exact reason.
Most often new roofs can be installed in the winter but you must use knowledgeable, skilled roofers like the roofers at Sunrise Roofing & Chimney.
New shingle roof installations can be done at above freezing temperatures during the winter so long as the roofer is experienced and knowledgeable in colder weather installations. The pressure on the nail gun needs to be set correctly. This is because the Spring weather will come along and cause the self-adhering shingles to continue to adhere together. The installation has to be done mindfully in order to prepare for that. If you use roofers who are thoughtful and experienced in this area your new shingle roof will be installed just as beautifully and reliably in the winter as it could in any other season.
Some flat roofs that use "self adhering" systems can only be installed at higher temperatures as determined by the manufacturer's instructions. However, flat roofing systems that are not self adhering (they either use torches or they are mechanically attached) can be done in cold weather.
Other roofing systems like metal, slate, composites and cedar shake are held together by fasteners and do not self-adhere; therefore the installation of these types of roofs is the same in any weather.
Keep in mind it's hot on the roof! Due to the suns reflection on dark colored shingles the temperature on the roof is usually about 70% higher than on the ground. Because of this we find the most desirable temperature range to install new roofs is about fifty to sixty degrees.
Our guarantee doesn't stop in the winter! We offer a ten year guarantee on labor and up to a thirty year guarantee on materials (depending on the manufacturer).
If you're facing a roof repair or installation and the winter is upon us just request an estimate! One of our knowledgeable technicians will come to you to explain what's best in your specific situation. At Sunrise Roofing & Chimney we care more about providing you with lasting quality and durability than we do about making a quick sale. Therefore we will analyze the severity of the repair, type of roof, weather conditions, etc; and provide you with an estimate and time frame that benefits you.
Don't hesitate having your roof inspected in any weather. If your roof is damaged waiting until Spring can be more costly. Request a free estimate from Sunrise Roofing & Chimney today!