Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8785779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:27:00+00:00 2026-06-13T21:27:00+00:00

I feel like a total noob posting here. I know CSS, HTML, and XML

  • 0

I feel like a total noob posting here. I know CSS, HTML, and XML pretty well but have always avoided JS. I know very little javascript and recently started a Lynda.com course to catch up. Sorry for my ignorance. As such, I am really struggling learning Google Apps Script. Obviously, I need to learn JS before I can make sense of any of it.

The school I work for (5000 students) has set up an online curriculum. I created the curriculum in the form of thousands of google document worksheets. These worksheets are linked on various websites.

The problem we are facing is that when students open the documents, they have to make a copy of them before they can edit them (I of course don’t want them to be able to edit the originals). This really sucks for students using mobile browsers on their tablets as making a copy in Google Docs doesn’t really work well when using the desktop UI on mobile devices.

I know this kind of thing can be automated with script. I’ve looked here, and low and behold, it works! I’m pissing my pants with joy as I’ve been searching for such functionality for three years. (Yes, I know that’s sad).

So, what I’m asking is, would anyone be willing to help a noob figure out how to adapt this code so that students click a button on a website lesson and it automatically makes and opens a copy of the worksheet in a new tab?

/**
 * Copy an existing file.
 *
 * @param {String} originFileId ID of the origin file to copy.
 * @param {String} copyTitle Title of the copy.
 */
function copyFile(originFileId, copyTitle) {
  var body = {'title': copyTitle};
  var request = gapi.client.drive.files.copy({
    'fileId': originFileId,
    'resource': body
  });
  request.execute(function(resp) {
    console.log('Copy ID: ' + resp.id);
  });
} 

Spending all day yesterday learning Javascript, I’ve still got a long way to go. Not sure how long it’ll take for me to be able to figure this out on my own.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:27:01+00:00Added an answer on June 13, 2026 at 9:27 pm

    You can certainly do this with Apps Script. Only takes a couple of lines. In fact, you can use just the version I wrote below.

    Here is how I would do it –

    1. Ensure you original document is at least read enabled for the folks that will be accessing it.

      Access rights

    2. Grab the fileId from the URL –

      enter image description here

    3. Write a web app in Apps Script with the following code –

      function doGet(e) {
        //file has to be at least readable by the person running the script
        var fileId = e.parameters.fileId;  
        if(!fileId){
          //have a default fileId for testing. 
          fileId = '1K7OA1lnzphJRuJ7ZjCfLu83MSwOXoEKWY6BuqYitTQQ'; 
        }
        var newUrl = DocsList.getFileById(fileId).makeCopy('File copied to my drive').getUrl(); 
        return HtmlService.createHtmlOutput('<h1><a href="'+newUrl+'">Open Document</a></h1>');
      }
      
    4. Deploy it to run as the person accessing the app.

      deploy settings

    One key thing to remember is that a web app built by Apps Script cannot force open a new window automatically. Instead we can show a link which is clickable into the document in edit mode.

    You can see it in action here (will create some dummy file) –

    https://script.google.com/macros/s/AKfycbyvxkYqgPQEb3ICieywqWrQ2-2KWb-V0MghR2xayQyExFgVT2h3/exec?fileId=0AkJNj_IM2wiPdGhsNEJzZ2RtZU9NaHc4QXdvbHhSM0E

    You can test this by putting in your own fileId.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel like I'm way overthinking this problem, but here goes anyway... I have
I feel like such a noob asking this but, for some reason a horizontal
I feel like I've only ever seen this here on SO, but I can't
I feel like there's a pretty simple way to do this, but I'm not
I feel like this is something I should already know, but I'm just not
Ok, I feel like a total idiot. I have read the docs and still
Do educate me about XML, I feel like a total dunce. I'm supposed to
I feel like a total n00b for not understanding what I'm doing wrong, but
I feel like I'm asking a lot of questions, but I keep getting stuck.
I feel like I'm missing something obvious, but I can't work out why my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.