We are using a Google Spreadsheet script to send us reformatted email.
Problem: We are wondering if there is a way to retain minimal formatting such as line breaks for the "strEnquirerMessage" cell for the following script.
I have tried including htmlBody somehow but no luck so far. Any help is greatly appreciated. Thank you.
User emails this message in contact form:
Line 1
Line 2
Line 3
We currently receive this in the email from this script: Line 1 Line 2 Line 3
Goal is to receive this:
Line 1
Line 2
Line 3
var strEnquirerName = values[row][1];
var strEnquirerEmail = values[row][2];
var strEnquirerAddress = values[row][3];
var strTopic = values[row][4];
var strEnquirerProducts = values[row][5];
var strEnquirerMessage = values[row][6];
var strMessageBody = "<b>NAME:</b> " + strEnquirerName +
"<br/><br/><b>EMAIL:</b> " + strEnquirerEmail +
"<br/><br/><b>ADDRESS:</b> " + strEnquirerAddress +
"<br/><br/><b>TOPIC:</b> " + strTopic +
"<br/><br/><b>PRODUCTS:</b> " + strEnquirerProducts +
"<br/><br/><b>MESSAGE:</b> " + strEnquirerMessage;
MailApp.sendEmail("your#emailaddress.com", strEnquirerEmail, " Contact form from " + strEnquirerName + " - " + strEnquirerEmail + " Re: " + strTopic, strMessageBody);
Thanks to this post, I have found the answer. Below is the updated line from the above code:
var strEnquirerMessage = values[row][6].replace(/\n/g, '<br>');
Beside the cell value is code to replace Google Spreadsheet's new line character with a line break. Hope this helps others.
Related
I'm receiving a gmail from the below code, but NOT the form values that I want to be included. I'm trying have a Google Form (Sheet) send an email to me (a teacher) when a student would type an important or alarming keyword in one of the form's fields (col J).
Picture a Google form with essentially the following fields:
A - Date/time stamp
B - email address collection
C - Name (short answer text)
D - what did you learn or work on yesterday? (long answer text)
E - How are you generally feeling today? (multiple choice)
F - Are you tired today? (multiple choice)
G - Are you stressed out today? (multiple choice)
H - What have you going on today? (bunch of checkboxes)
I - What could be "cool" or "good" about today? (long answer text)
J - (optional) Feel free to tell me anything more (long answer text)
If the student types any alert words, like "die" or "drugs" and so on in the last column (column J), I'd like to get a gmail with a summary of all the info on the row. So far, I've set up a trigger and am only getting a gmail with a subject and message, but the message DOES NOT contain the concatenated vars values.
ALSO, the gmail's subject DOES NOT contain the concatenated studname, which would be helpful. I'm curious how you'd fix this code.
THANK YOU!!
function checkComments(){
var commentsRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2").getRange("J2");
var sheet = SpreadsheetApp.getActive().getSheetByName("Sheet2");
var lastrow = sheet.getLastRow();
var comments = sheet.getRange('J' + lastrow).getValue();
if (comments === '.*drug.*'||'.*die.*'||'.*emotion.*'||'.*suicide.*'||) //many more root key words will be added in here in this |OR| format
{
// Send Alert Email.
var timestamp = sheet.getRange('A' + lastrow).getValue();
var studname = sheet.getRange('C' + lastrow).getValue();
var studemail = sheet.getRange('B' + lastrow).getValue();
var feelings= sheet.getRange('E' + lastrow).getValue();
var tired= sheet.getRange('F' + lastrow).getValue();
var stressed= sheet.getRange('G' + lastrow).getValue();
var studwork = sheet.getRange('H' + lastrow).getValue();
var cool = sheet.getRange('I' + lastrow).getValue();
var results = timestamp + ' \n ' + studname + ' \n ' + studemail + ' \n ' + feelings + ' \n ' + tired + ' \n ' + stressed + ' \n ' + studwork + ' \n ' + cool + ' \n ' + comments;
var emailAddress = 'my email address';
var message = 'Alert from the daily survey!\n' + results;
var subject = 'Daily Survey Alert from ' + studname;
MailApp.sendEmail(emailAddress, subject, message);
}
}```
To match a keyword, replace the
if (comments === '.*drug.*'||'.*die.*'||'.*emotion.*'||'.*suicide.*'||)
with
if(!!comments.match(/drug|die|emotion|suicide/))
I've fixed a bit your code and it seems work for me:
function checkComments() {
var sheet = SpreadsheetApp.getSheetByName('Sheet2');
var lastRow = sheet.getLastRow();
// it works faster when you grab all the row at once
var row = sheet.getRange('A'+lastRow+':J'+lastRow).getValues().flat();
var comments = row[9];
var words = ['drug','die','emotion','suicide'];
if (words.filter(w => comments.includes(w)).length == 0) return;
var emailAddress = 'your#mail.com';
var subject = row[2];
var message = row.join('\n');
MailApp.sendEmail(emailAddress, subject, message);
}
Probably it makes sense to use RegEx to search these words in comments. But I'm not sure if you're ready to dive so deep.
In Google sheets, I get a "formula parse error" in the cell this code edits:
var A1one = 'C4';
var A1two = 'B4';
var A1three = 'B4';
var wholeFormula = '=if(today()<D$1,,' + A1one + '+if(isNumber(' + A1two + '),' + A1three + ',0)';
var wholeFormulaA1 = '=if(today()<D$1,,C4+if(isNumber(B4),B4,0))';
trackCell1.setFormula(wholeFormula);
But if I change the code as follows it works fine (only change is in last line):
var A1one = 'C4';
var A1two = 'B4';
var A1three = 'B4';
var wholeFormula = '=if(today()<D$1,,' + A1one + '+if(isNumber(' + A1two + '),' + A1three + ',0)';
var wholeFormulaA1 = '=if(today()<D$1,,C4+if(isNumber(B4),B4,0))';
trackCell1.setFormula(wholeFormulaA1);
wholeFormula and wholeFormulaA1 should be identical. Why does Google Sheets treat them differently?
I assume this is some kind of recalculation error. If I run the first code example above, and the cell displays #ERROR!, I can fix it by double clicking the cell and hitting ENTER on the keyboard. This forces the sheet to recalculate (I guess?), and the proper result of the formula is displayed in the cell.
But how do I get Google Sheets to update the cell automatically when using the first code example?
I guess you missed ) at the end, try:
var try = '=if(today()<D$1,,' + A1one + '+if(isNumber(' + A1two + '),' + A1three + ',0))';
To force script recalculate the formula, use SpreadsheetApp.flush();
I can fix it by double clicking the cell and hitting ENTER on the
keyboard. This forces the sheet to recalculate (I guess?), and the
proper result of the formula is displayed in the cell.
I think when you reenter the formula manually, it checks if ) is missed and repairs this automatically. This won't happen when you enter the formula by script.
I am trying to create a Detail-Master page using OData service in SAPUI5. Everything works fine in the Master page.
When I clicked on the item on the Master page, it brings down to the Detail page, but I could not get the data in the Detail page.
I have put the alert function to debug in the Detail page. This code will never be executed.
var oList = new sap.m.List({headerText: "Material Details", items:
[
new sap.m.DisplayListItem({label:"Material:",value:"{Material}"}),
new sap.m.DisplayListItem({label:"Material:",value:{
path:"Materials",
formatter:function(iValue){
alert('Here!!');
var test = this.getBindingContext();
console.log('SS:' + test);
var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " # "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() + ":"
+ currentdate.getSeconds();
return currentdate + " sq km";
}
}})
]});
Any idea why? do we need to get the model ?
Herer is the full source code:
https://github.com/ferrygun/SAPUI5
I've a student form which there's location inside the form, when I run the app and show the form it'll look like this
Location : Jl Excel Road Ring No.36 SINGAPORE, 10110
But I want to make the location in two line like this
Location : Jl Excel Road Ring No.36
SINGAPORE, 10110
here's the gsp
<td><g:message code="location.label"/></td>
<td>${studentInstance.location}</td>
and this is the service in def show
def loc = Location.findByTidAndDeleteFlag(params.tid, "N")
if(loc != null){
studentInstance.location = loc.address1 + " " + loc.city + ", " + loc.zipCode
}
else{
studentInstance.location = ""
}
Use the br tag
studentInstance.location = loc.address1 + "<br/> " + loc.city + ", " + loc.zipCode
Then you can render directly the HTML unescaped like this:
<%=studentInstance.location%>
The default codec is probably HTML in your configuration.
Check the value of grails.views.default.codec
For more information read this:
http://grails.org/doc/2.2.1/ref/Plug-ins/codecs.html
I believe that starting from Grails 2.3.x the default views codec is HTML with XML escaping in order to prevent XSS attacks.
This is a bad approach but you can try
studentInstance.location = loc.address1 + "<br> " + loc.city + ", " + loc.zipCode
Generally, I would have each of the element of address available in view so that the styling is flexible in view than in controller, something raw would look like:
<td><g:message code="location.label"/></td>
<td>${model.address1} <br> ${model.city}, ${model.zipCode}</td>
How can I add a country selection field to Jira?
I've posted the the answer hoping it will help others, as well as hearing your thought on it..
Add a test field and get it's ID, for example let's say it's "customfield_11111". Than add it the following description:
<script src="https://jira.com/getCountrySelect.js">
</script>
You can write the code directory in the description, but I found it easier to backup and update the scripts this way. Then, in you app-data folder create the file getCountrySelect.js (replace the fieldID with your filed id):
var fieldId = "customfield_11111";
AJS.$(document).ready(function() {
var country = AJS.$("#" + fieldId).val();
AJS.$("#" + fieldId).parent().append("<select class='select' id='" + fieldId + "' name='" + fieldId + "'></select>");
var select = AJS.$("select#" + fieldId);
select.append("<option>Afghanistan</option>");
select.append("<option>Albania</option>");
select.append("<option>Algeria</option>");
select.append("<option>Andorra</option>");
select.append("<option>Angola</option>");
select.append("<option>Antigua & Deps</option>");
select.append("<option>Argentina</option>");
select.append("<option>Armenia</option>");
select.append("<option>Australia</option>");
select.append("<option>Austria</option>");
select.append("<option>Azerbaijan</option>");
select.append("<option>Bahamas</option>");
select.append("<option>Bahrain</option>");
select.append("<option>Bangladesh</option>");
select.append("<option>Barbados</option>");
select.append("<option>Belarus</option>");
select.append("<option>Belgium</option>");
select.append("<option>Belize</option>");
select.append("<option>Benin</option>");
select.append("<option>Bhutan</option>");
select.append("<option>Bolivia</option>");
select.append("<option>Bosnia Herzegovina</option>");
select.append("<option>Botswana</option>");
select.append("<option>Brazil</option>");
select.append("<option>Brunei</option>");
select.append("<option>Bulgaria</option>");
select.append("<option>Burkina</option>");
select.append("<option>Burundi</option>");
select.append("<option>Cambodia</option>");
select.append("<option>Cameroon</option>");
select.append("<option>Canada</option>");
select.append("<option>Cape Verde</option>");
select.append("<option>Central African Rep</option>");
select.append("<option>Chad</option>");
select.append("<option>Chile</option>");
select.append("<option>China</option>");
select.append("<option>Colombia</option>");
select.append("<option>Comoros</option>");
select.append("<option>Congo</option>");
select.append("<option>Congo {Democratic Rep}</option>");
select.append("<option>Costa Rica</option>");
select.append("<option>Croatia</option>");
select.append("<option>Cuba</option>");
select.append("<option>Cyprus</option>");
select.append("<option>Czech Republic</option>");
select.append("<option>Denmark</option>");
select.append("<option>Djibouti</option>");
select.append("<option>Dominica</option>");
select.append("<option>Dominican Republic</option>");
select.append("<option>East Timor</option>");
select.append("<option>Ecuador</option>");
select.append("<option>Egypt</option>");
select.append("<option>El Salvador</option>");
select.append("<option>Equatorial Guinea</option>");
select.append("<option>Eritrea</option>");
select.append("<option>Estonia</option>");
select.append("<option>Ethiopia</option>");
select.append("<option>Fiji</option>");
select.append("<option>Finland</option>");
select.append("<option>France</option>");
select.append("<option>Gabon</option>");
select.append("<option>Gambia</option>");
select.append("<option>Georgia</option>");
select.append("<option>Germany</option>");
select.append("<option>Ghana</option>");
select.append("<option>Greece</option>");
select.append("<option>Grenada</option>");
select.append("<option>Guatemala</option>");
select.append("<option>Guinea</option>");
select.append("<option>Guinea-Bissau</option>");
select.append("<option>Guyana</option>");
select.append("<option>Haiti</option>");
select.append("<option>Honduras</option>");
select.append("<option>Hungary</option>");
select.append("<option>Iceland</option>");
select.append("<option>India</option>");
select.append("<option>Indonesia</option>");
select.append("<option>Iran</option>");
select.append("<option>Iraq</option>");
select.append("<option>Ireland {Republic}</option>");
select.append("<option>Israel</option>");
select.append("<option>Italy</option>");
select.append("<option>Ivory Coast</option>");
select.append("<option>Jamaica</option>");
select.append("<option>Japan</option>");
select.append("<option>Jordan</option>");
select.append("<option>Kazakhstan</option>");
select.append("<option>Kenya</option>");
select.append("<option>Kiribati</option>");
select.append("<option>Korea North</option>");
select.append("<option>Korea South</option>");
select.append("<option>Kosovo</option>");
select.append("<option>Kuwait</option>");
select.append("<option>Kyrgyzstan</option>");
select.append("<option>Laos</option>");
select.append("<option>Latvia</option>");
select.append("<option>Lebanon</option>");
select.append("<option>Lesotho</option>");
select.append("<option>Liberia</option>");
select.append("<option>Libya</option>");
select.append("<option>Liechtenstein</option>");
select.append("<option>Lithuania</option>");
select.append("<option>Luxembourg</option>");
select.append("<option>Macedonia</option>");
select.append("<option>Madagascar</option>");
select.append("<option>Malawi</option>");
select.append("<option>Malaysia</option>");
select.append("<option>Maldives</option>");
select.append("<option>Mali</option>");
select.append("<option>Malta</option>");
select.append("<option>Marshall Islands</option>");
select.append("<option>Mauritania</option>");
select.append("<option>Mauritius</option>");
select.append("<option>Mexico</option>");
select.append("<option>Micronesia</option>");
select.append("<option>Moldova</option>");
select.append("<option>Monaco</option>");
select.append("<option>Mongolia</option>");
select.append("<option>Montenegro</option>");
select.append("<option>Morocco</option>");
select.append("<option>Mozambique</option>");
select.append("<option>Myanmar, {Burma}</option>");
select.append("<option>Namibia</option>");
select.append("<option>Nauru</option>");
select.append("<option>Nepal</option>");
select.append("<option>Netherlands</option>");
select.append("<option>New Zealand</option>");
select.append("<option>Nicaragua</option>");
select.append("<option>Niger</option>");
select.append("<option>Nigeria</option>");
select.append("<option>Norway</option>");
select.append("<option>Oman</option>");
select.append("<option>Pakistan</option>");
select.append("<option>Palau</option>");
select.append("<option>Panama</option>");
select.append("<option>Papua New Guinea</option>");
select.append("<option>Paraguay</option>");
select.append("<option>Peru</option>");
select.append("<option>Philippines</option>");
select.append("<option>Poland</option>");
select.append("<option>Portugal</option>");
select.append("<option>Qatar</option>");
select.append("<option>Romania</option>");
select.append("<option>Russian Federation</option>");
select.append("<option>Rwanda</option>");
select.append("<option>St Kitts & Nevis</option>");
select.append("<option>St Lucia</option>");
select.append("<option>Saint Vincent & the Grenadines</option>");
select.append("<option>Samoa</option>");
select.append("<option>San Marino</option>");
select.append("<option>Sao Tome & Principe</option>");
select.append("<option>Saudi Arabia</option>");
select.append("<option>Senegal</option>");
select.append("<option>Serbia</option>");
select.append("<option>Seychelles</option>");
select.append("<option>Sierra Leone</option>");
select.append("<option>Singapore</option>");
select.append("<option>Slovakia</option>");
select.append("<option>Slovenia</option>");
select.append("<option>Solomon Islands</option>");
select.append("<option>Somalia</option>");
select.append("<option>South Africa</option>");
select.append("<option>Spain</option>");
select.append("<option>Sri Lanka</option>");
select.append("<option>Sudan</option>");
select.append("<option>Suriname</option>");
select.append("<option>Swaziland</option>");
select.append("<option>Sweden</option>");
select.append("<option>Switzerland</option>");
select.append("<option>Syria</option>");
select.append("<option>Taiwan</option>");
select.append("<option>Tajikistan</option>");
select.append("<option>Tanzania</option>");
select.append("<option>Thailand</option>");
select.append("<option>Togo</option>");
select.append("<option>Tonga</option>");
select.append("<option>Trinidad & Tobago</option>");
select.append("<option>Tunisia</option>");
select.append("<option>Turkey</option>");
select.append("<option>Turkmenistan</option>");
select.append("<option>Tuvalu</option>");
select.append("<option>Uganda</option>");
select.append("<option>Ukraine</option>");
select.append("<option>United Arab Emirates</option>");
select.append("<option>United Kingdom</option>");
select.append("<option>United States</option>");
select.append("<option>Uruguay</option>");
select.append("<option>Uzbekistan</option>");
select.append("<option>Vanuatu</option>");
select.append("<option>Vatican City</option>");
select.append("<option>Venezuela</option>");
select.append("<option>Vietnam</option>");
select.append("<option>Yemen</option>");
select.append("<option>Zambia</option>");
select.append("<option>Zimbabwe</option>");
AJS.$("input#" + fieldId).remove();
AJS.$('#' + fieldId + ' option:contains('+country+')').attr('selected', 'selected');
});
Hope it will help you too :)