Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I need to copy and rename a base form (a spreadsheet) to several other forms in Google Docs. Imagine I have the following form:

  • My Base Form - @name (@course)

After running the script or whatever, I will end up with those forms:

  • My Form Copy - John Doe (Computer Science)
  • My Form Copy 2 - Donald (Arts)
  • ...
  • My Form Copy 15 - Andrea (Music)

Any idea on how can I do that?

share|improve this question
    
Can you share a doc with us? –  Jacob Jan Tuinstra Feb 9 '13 at 22:49
    
If this is about the question, never mind, I figured it out already :) –  Dovyski Feb 12 '13 at 15:54
    
Perhaps you can share this solution with us, Q&A style? –  Jacob Jan Tuinstra Feb 12 '13 at 17:19
    
Ok, I've shared my solution. I hope it can help. Thanks for the bootstrap, Jacob! –  Dovyski Feb 25 '13 at 14:15
add comment

1 Answer

After some research, I figured it myself. Here is my solution if someone faces the same problem and needs a script for that:

Code

function makeForms() {
  // Google Spreadsheet ID
  var BASE_FORM_ID = "0AlDgVsiNXDhjdFlRTFVBeG5rNmprb3kHNxd1ItSFE";

  // object that holds the information 
  var aNames = [     
    {name: "Prof. Fernando", course: "Course name"},
    {name: "Prof. Rafael", course: "Course name"}
  ];

  // creation of variables
  var aSpreadsheet, aNewForm, aCurrentName = "";
  var aBaseForm = DocsList.getFileById(BASE_FORM_ID);

  // iterate over the names
  for(var i = 0; iLen = aNames.length; i < iLen; i++) {
    // set name
    aCurrentName = aNames[i].course+" ("+aNames[i].name+")";

    // make copy
    aNewForm = aBaseForm.makeCopy("Evaluation for " + aCurrentName);  

    // open spreadsheet and retrieve ID
    aSpreadsheet = SpreadsheetApp.openById(aNewForm.getId());

    // log the Url's 
    Logger.log(aCurrentName + "  "+aSpreadsheet.getFormUrl());
  }
}

References

share|improve this answer
    
Sorry, I don't have the rep points to leave an actual comment (a bug with the stackoverflow system): References to how you figured this out would be helpful as I have no clue what some of these functions are doing. Moreover, commenting on the code could be just as helpful. Thanks and Regards –  virtualxtc Jun 29 '13 at 22:21
    
Not a bug. By design. –  Al E. Jun 30 '13 at 4:55
    
@user1059398 I started at the Google Apps script page. From there, I searched for functions that would help me, such as "how to open a spreadsheet?". I coded the solution by assembling my findings. –  Dovyski Jul 5 '13 at 13:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.