简体   繁体   中英

Writing a script to Clear Data at a specific time, Archive the cleared data and if possible move certain fields to a separate sheet

I have a google form that I am trying to have people answer questions to each day. It is mandatory that this form is completed before they come to the facility. I need a script to clear the data in the Response Tab at midnight each night and I need that data that is being cleared to be archived in a separate sheet if possible. A bonus feature would if as the responses come in each day, the could populate on a separate sheet with 4 fields, "Student ID", "Last Name", "First Name" and "Cleared"

I know I'm asking a lot! The most important thing is the clearing daily and being able to archive the previous day's data (even if it has to be a tab in that file)

To be fair I'm also very new to using scripts if I have to do anything special besides add script I might need some guidance there as well.

Any help anyone could give would be awesome!!!

As Nabnub has already indicated, this is really too much for one question. However, the appointment scheduling system that I made for my tutoring website, (see tutoringbyroger.com ), does something quite similar to what you would need, so I will give you some quick pointers below on what worked for me:

  1. You will need to open up the form where the information comes in and go into the script editor from there. Once in there, this function should get you started:
function closeForm(e){
    // First we will get the information they entered and parse it
    // into an array of strings:
  
    var responsesArray = e.response.getItemResponses();
    var txtResponsesArray = [];
  
    var len = responsesArray.length;
    for(var i=0; i < len; ++i){
      txtResponsesArray[i] = responsesArray[i].getResponse();
    }
    // We can now do stuff with the strings in txtResponsesArray, like add them to
    // a spreadsheet or something.
}
  1. In the script editor you will need to click on triggers, and add a trigger to run the above function when the form is closed. That way, you can capture the data and process it the instant it is submitted.

  2. Create a separate function whose sole purpose is to clear out the information that you would like to clear. This can be from the form or the spreadsheet, or both. It can be in the same script file, just outside of the closeForm() function.

  3. Create another trigger to run the function that does the deleting when you would like that task done.

Anyhow, that is a taste of what you will need to get started. Here are some relevant links to some documentation you might find useful:

How to open a form . (Note: the ID comes from the url of the form when you edit it)

How to open a spreadsheet .

I hope that gives you some idea of where to start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM