Reputation: 71
Someone kindly pointed out to me (outside of Stack Overflow) that the Form ID which identifies the form can be found in the web address. Example:
https://docs.google.com/forms/d/
1y9XMjvZi_wlFC2FN64cdafIyGuM_7UOsn1Q61PXv5MQ/edit
Where the bolded text is the Form ID.
Apologies in advance, as I am not an experienced script writer and may use improper jargon.
But - I found the response to this question when googling about how to find the Form ID element in a Google Form, but the answer is old and my problem is similar. I have tried searching the "Inspect Element" data and still cannot identify the ID attribute. I've tried searching the code for:
Still no luck. Does anyone have an updated suggestion for finding the Form ID? For reference, I am using the script below as my starting point. This is taken from a different/old form, but is similar in functionality so I was hoping to leverage it. I am trying to find my Form's ID (such as that as in line 6-7).
/**
* @NotOnlyCurrentDoc
* Limit OAuth scope to only current spreadsheet rather than all sheets in drive
*/
function onSubmit(e) {
var form = FormApp.openById('1eccBQ7Bs34Z54keGHeR8HDXmiP1UqxMi9vSDWNv6zgs');
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Master');
var data = sheet.getDataRange().getValues();
//var urlCol = 26;
var responses = form.getResponses();
var timestamps = [], urls = [], resultUrls = [];
for (var i = 0; i < responses.length; i++) {
timestamps.push(responses[i].getTimestamp().setMilliseconds(0));
urls.push(responses[i].getEditResponseUrl());
}
for (var j = 1; j < data.length; j++) {
resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']);
}
sheet.getRange(2, urlCol = 27, resultUrls.length).setValues(resultUrls);
return resultUrls;
};
Upvotes: 7
Views: 47948
Reputation: 38346
As the OP mentioned in the question body, the Form ID could be found in the Google Form URL, but hte OP missed to mention that this URL is the edit URL, not the "view" URL.
The form owner also could find the form ID by using the web-browser developer tools by searching for data-redirect-url
which has assigned the Form URL:
data-redirect-url="https://docs.google.com/forms/d/form_id/edit?usp=redirect_edit_m2"
As mentioned by the OP the Form ID is between https://docs.google.com/forms/d/
and /edit
.
Besides looking at the Form URL, the form ID could be retrieved by using Google Apps Script. The easier way is to use a bounded script similar to this:
function getActiveFormID(){
const id = FormApp.getActiveForm().getId();
console.log(id);
}
Another way is by using the Drive Service. The following example assumes that there is only one file named "My Form":
function getFormId(){
const id = DriveApp.searchFiles(`title contains "My Form"`).next().getId();
console.log(id);
}
Upvotes: 6
Reputation: 7
From Google Chrome, open the form (view mode, not edit).
Hit F12.
In the Elements window pain,
expand <body>
expand <script type = "text/javascript" nonce> == $0
You should see:
var FB_PUBLIC_LOAD_DATA
with each element you created on their form and their respective Element ID.
Upvotes: -2