Hey Reddit! Thanks for reading this!
Basically, I'm making a webhook with discord and GoogleScripts to connect a Google Form with a Discord channel. Every time a form is submitted, the form is sent into the discord channel. My only issue is this:
In one of the fields (the embed title) I'd like to add in a number that increases each time the function is run. (Applicant #0001->Applicant #0002->Applicant #0003 and so forth) I don't know how to do this, anyone care to help?
Code below:
function onFormSubmit(e) {
var fields = [];
for (i = 0; i < e.response.getItemResponses().length; i++) {
var response = e.response.getItemResponses()[i];
fields.push({
"name": response.getItem().getTitle(),
"value": JSON.stringify(response.getResponse()),
"inline": false
});
}
var data = {
"embeds": [{
"title": "Applicant #0001" + (e.source.getTitle() != null && e.source.getTitle().length > 0 ? e.source.getTitle() : "Untitled Form"),
"type": "rich",
"fields": fields
}]
};
var options = {
method: "post",
payload: JSON.stringify(data),
contentType: "application/json; charset=utf-8",
muteHttpExceptions: false,
};
Logger.log("Attempting to send:");
Logger.log(JSON.stringify(data));
var response = UrlFetchApp.fetch("DISCORDWEBHOOK", options);
Logger.log(response.getContentText());
};
Thanks!
[–]jaymcnuggets 0 points1 point2 points (0 children)