I have an app script that executes when the a google form response is submitted. The app script is attached to the response google sheet.
I want to send out a an email by formatting the responses but since google form does not allow formatting of answers I have to do it in the app script.
The user will enter the response for a question in multiple lines. I want to take that response and create and unordered list for that questions.
For example: the user will enter the following response this is a test this should be another list item. another one.
I want to format this as
- this is a test
- this should be another list item.
- another one.
to do this I have to get the response from the google sheet cell and split by new line (\n). For some reason I am unable to do so.
function onFormSubmit(e) {
var values = e.namedValues;
var htmlBody = '';
for (Key in values) {
Logger.log(Key + ' : '+ values[Key]);
try {
Logger.log(JSON.stringify(values[Key]));
} catch(error) {
Logger.log(error);
}
htmlBody += createSection(Key, values[Key]);
GmailApp.sendEmail('abc@org.com', 'sending email', '', {htmlBody:htmlBody});
}
function createSection(sectionName, values) {
Logger.log(sectionName + ' : '+ values + ' Length: ' + values.length);
var linesHtml = createBulletList(values);
var sectionHtml = '<h1>' + sectionName + '</h1>' + '<p><br></p>';
sectionHtml += '<ul>' + linesHtml + '</ul>' + '<p><br></p>';
return sectionHtml;
}
function createBulletList(values) {
var listHtml = '';
Logger.log('createBulletList ' + values + ' Length: ' + values.length);
//listHtml += values.forEach(listItem);
listHtml += listItem(values);
Logger.log(listHtml);
return listHtml;
}
I have tried split but for some reason it does not work on values[Key] object. I have tried JSON.stringify to flatten the object but the split('\n') still does not work on the string.
Any help will be appreciated.
