Reputation: 47
I'm trying to remove responses from Google forms that are older than a set age. I have a script to do this for the sheet, but this does not remove the responses from the form. Removing all responses from the form is not an option as I need to retain the responses not older than the set age. This is the script which works on the sheet, which I need an equivalent for on the form.
function DeleteOldEntries() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//give your sheet name below instead of Sheet1
var sheet = ss.getSheetByName("Sheet 1");
var datarange = sheet.getDataRange();
var lastrow = datarange.getLastRow();
var currentDate = new Date();
var oneweekago = new Date();
oneweekago.setDate(currentDate.getDate() - 1095);
for (i=lastrow;i>=2;i--) {
var tempdate = sheet.getRange(i, 1).getValue();
if(tempdate < oneweekago)
{
sheet.deleteRow(i);
}
}
}
Upvotes: 0
Views: 1363
Reputation: 1461
I've created a Form
and I managed to delete the submits older than a week. There are a few methods that you have to use to achieve that goal:
Form
. You can use getActiveForm if you are using an Apps Script project contained in a Form
document. Otherwise, use openById or openByUrltimestamp
of each with getTimestampfunction deleteSubmissions(){
var oneweekago = new Date();
oneweekago.setDate(oneweekago.getDate() - 1095);
var form = FormApp.getActiveForm() // FormApp.openById() | FormApp.openByUrl()
var responses = form.getResponses()
for (var i=0; i<responses.length; i++){
var r = responses[i]
var responseTime = r.getTimestamp()
if (responseTime > oneweekago){
var id = r.getId()
form.deleteResponse(id)
}
}
}
Upvotes: 1
Reputation: 781
You need to write a script to delete the response from the Form same as you write for the spreadsheet.Please refer this link for deleting form single response by Id
Upvotes: 0