Reputation: 23
I was searching for a script to capture the IP Address of the person who submits the Form. I ended up writing this code in the response sheet:
/*
* Global Variables
*/
// Form
var formId = 'FromID';
// Sheet
var sheetName = 'Form Responses 1';
var columnName = 'IP Address';
// Responses starting row
var startRow = 2;
function UploadIPAddress_FromSheet(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
var columnIndex = headers[0].indexOf(columnName);
var data = sheet.getDataRange().getValues();
var form = FormApp.openById(formId);
for(var i = startRow-1; i < data.length; i++) {
if(data[i][0] && !data[i][columnIndex]) {
var ip = JSON.parse(UrlFetchApp.fetch('https://api6.ipify.org?format=json')).ip;
sheet.getRange(i+1, columnIndex+1).setValue(ip);
}
}
}
This works as expected in that when I run the script manually it populates the "IP Address" column of the last response row with my IP address. However, when I submit the form with a trigger to run the script, it does the same but with the Google server IP address.
Any idea how I can achieve the first output by the Form submission?
Many thanks
Upvotes: 0
Views: 4470
Reputation: 289
Unfortunately, it's not possible. You have to look into alternative form services.
Upvotes: 2