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

  • Home
  • SEARCH
  • 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 8184839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:38:45+00:00 2026-06-07T01:38:45+00:00

I’m Working on creating script that will perform the actions described below. so far,

  • 0

I’m Working on creating script that will perform the actions described below. so far, I’ve managed to get the first two parts to function, but am now stuck on getting anything more to work. I’ve reviewed several response forums and tried the suggestions, but no success.

Desired script flow:
form submitted from spreadsheet form
completes fields:
Timestamp
Username (email collected on submission)
Student
Grade
Intervention Plan
Core Reading/Math
Team (email list)

1 script runs onFormSubmit that then creates a copy of a template document, renames that new copy to the e.value “student” submitted in form,

2 then replaces selected text strings within the document with values submitted in the form.

3 Add editors to new document and sends notification with desired instructions

4 creates event (one week from submission date) event details include instructions and link to shared document for team members to complete with their input, sends event invitation to email list.

Here is the working script so far.

function formSubmitValues(e) {

  var timeStamp = e.values[0];
  var userEmail = e.values[1];
  var student = e.values[2];
  var grade = e.values[3];
  var conern = e.values[4];
  var readingCore = e.values[5];
  var mathCore = e.values[6];
  var interventions = e.values[7];
  var team = e.values[8].toString(); // "just to be sure"..Henrique says add .toString      this allowed the replaceText part to work

  //Makes copy of template document and renames
  var tempID = ("1Rq0pDAnuGNfL6W3GB0ZuLeWM2uYzHpKzoyxoXlwjtgE") // use document ID from Template Document
  var copyId = DocsList
              .getFileById(tempID)
              .makeCopy(student + " Initial Referral") // names new copy as student's name
              .getId();

// trying to add editors to new document using email list generated in form submit value of "team"
DocsList.getFileById(copyId).addEditors([team]); 




// replaces text within template with selected fields from formSubmitValues
  var doc = DocumentApp.openById(copyId)  
  var body = doc.getActiveSection();

    body.replaceText("%STUDENT%", student);
    body.replaceText("%DATE%", timeStamp);
    body.replaceText("%TEACHER%", userEmail);
    body.replaceText("%TEAM%", team);

  return doc;

}

REPORTED ISSUE RESPONSE: Here is what they said: “The function takes an array or strings, like: DocsList.getFileById(copyId).addEditors(['parent@domain.com', 'parent2@domain.com']);

I tried entering emails directly into script like this and things worked.
So my problem is not the ‘addEditors method, but lies in getting the form submitted emails to be passed correctly. Any suggestions on how I would do this?

I have tried what I believe to be all combinations of using .toString(), or not, and using .Split(‘,’).

RE-DEFINE PROBLEM : So it is an issue of how the emails are passed from the e.values form submit.

Here is where I’m at:
When I type emails into script directly: .addEditors(['parent@domain.com', 'email2@domain.net', 'email3@gmail.com']) it works, (I did have to move the addEditors method in the script to go right after the .makeCopy instead of at the end.)
This is what the Execution Transcript shows:
File.addEditors([[parent@domain.com, email2@domain.net]]) and it runs the rest of the script. note: One part I don’t understand is the single quotes i.e. ’email’ They must be typed in the script, but don’t show up on Transcript when run. I’ve tried putting them around emails in the form, but it makes them show in Transcript and still doesn’t run anyway.

So this is what script looks like now:

var tempID = ("1Rq0pDAnuGNfL6W3GB0ZuLeWM2uYzHpKzoyxoXlwjtgE") // use document ID from Template Document
var copyId = DocsList
              .getFileById(tempID)
              .makeCopy(student + " - TestingCopy") // names new copy as student's name + text
              .addEditors([team.split(',')])  
              .getId();

But when I use the var team with or without .split(',') it does not work. But in the Transcript it shows:
File.addEditors([[rreynolds@domain.net, parent@domain.com]])
which looks identical as to what shows when it does work, but that is the last thing shown in Transcript and editors are not added to document and the script does not finish.

I’m obviously not understanding something here. Is there a way I could get the emails in the team e.values to be treated in a way that the addEditors method is requiring? In the spreadsheet cell they appear as a CSV. i.e rreynolds@domain.net, parent@domain.com
Do they have to be read one at a time, or something?

I’m learning a lot, and appreciate all your help. I am sorry for the confusion with all the comments, but am not sure of the correct way to address issues in this forum. For example: should I go back and edit my original script to show the current version, or add it someplace else? I’m trying to keep the conversation flowing, so that it is easier for others to follow – Thanks rob

  • 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-07T01:38:47+00:00Added an answer on June 7, 2026 at 1:38 am

    please let me give a last (hopefully) clear answer : (thanks for sharing the spreadsheet, this is far more easy to work on 😉

    here is your code fully working.

    I have created some intermediate variables to show how it works.

        function formSubmitEditors(e) {
    
          // defines spreadsheet form events on submit of form.  This function formSubmitEditors is triggered on formSubmit
          var timeStamp = e.values[0];
          var fileName = e.values[1];
          var team = e.values[2].replace(/, /g,"|"); // remove unwanted spaces and commas replace by | for visibility ;-)
          Logger.log(team);// contains | as separators
          var teamArray = team.split('|');
          Logger.log(teamArray.length+'  :  '+teamArray);// check that it is an array of x elements
    
          //Makes copy of template document and renames
          var tempID = '1Rq0pDAnuGNfL6W3GB0ZuLeWM2uYzHpKzoyxoXlwjtgE' // use document ID from Template Document
          var copyId = DocsList
                      .getFileById(tempID)
                      .makeCopy(fileName + " - TestingCopy") // names new copy as student's name + text
                      .getId();                     // 
        var file = DocsList.getFileById(copyId).addEditors(teamArray);
    
        // replaces merged-text values within template with selected fields from formSubmitValues
          var doc = DocumentApp.openById(copyId)
          var body = doc.getActiveSection();
    
            body.replaceText("%FILE%", fileName);// you wrote %FILENAME% in place of %FILE%
            body.replaceText("%DATE%", timeStamp);
            body.replaceText("%TEAM%", team);// it will be shown with | as separators, if you don't like it replace team by teamArray.toString() to get commas again.
         }
    

    EDIT : I removed the toString() for team event, not necessary since e.parameters are already strings.

    EDIT2 : to be complete and do what you needed in the initial question you could replace the end of the code with this one that creates the Cal event on next week and sends invites with link to the doc.

      var file = DocsList.getFileById(copyId).addEditors(editorsArray);
      var fileurl = file.getUrl();
      Logger.log(fileurl)
    
    // replaces merged-text values within template with selected fields from formSubmitValues
      var doc = DocumentApp.openById(copyId)
      var body = doc.getActiveSection();
    
        body.replaceText("%FILE%", fileName);
        body.replaceText("%DATE%", timeStamp);
        body.replaceText("%MAILS%", editors);
    
      var Cal = CalendarApp.getCalendarsByName('testencodage')[0];// replace with your calendar name you want to use
      var newEvent = Cal.createAllDayEvent('Fill the questionnary', new Date(new Date(newtimeStamp).getTime()+7*24*3600*1000), { guests : e.values[2] , sendInvites : true , description :"Don't forget to fill this document "+fileurl})
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have two tables with like below codes: Table: Accounts id | username |
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.