Making string content strikethrough in Google Apps - javascript

I'm faced with a trivial but not-quick-to-get thing: I need to set the font of a string as a strike-through style.
I've tried search for similar solution on Stackoverflow but it wasn't much instructive and helpful.
What I do have:
var bookingDetails = "\nЗаезд: " + row[0] + "\nВыезд: " + row[1] + "\nНомер: " + "«" + row[2] + "»" + "\nТип размещения: " + row[3] + "\n" + "\nЦена за ночь: " + row[4] + " руб." + "\nВнесённый депозит: " + row[8] + " руб." + "\n" + "\nИмя и фамилия гостя: " + row[5] + "\nМобильный телефон: " + row[6] + "\nЭлектронная почта: " + row[7] + "\n" + "\nПримечание: " + row[11];
I need to make the content of bookingDetails striked out without changing anything in the sheet itself. I tried bookingDetails.setFontLine("line-through") but it didn't help by showing the error of "TypeError: Cannot find function setFontLine in object...".
Please, help me fix it.
Just letting you know that I'm very thankful for your attempt to help me in advance.
UPD № 1: I'm using Google Spreadsheets. If it does make sense.
UPD № 2: If it is not possible to make this strike-through transformation just in the script not explicitly in cells then I should add that bookingDetails is used in the email body to be sent through MailApp.sendEmail. So if it possible to transform the contents of bookigndbetails directly in the message body then let me know how to make it as quick as possible on the example of my script.
Hoping that know my goal is clear.

Here is a function that will set strikethrough the text
function setStrikethrough(range) {
var ss = SpreadsheetApp.getActiveSpreadsheet(); // Get the current spreadsheet.
var sheet = ss.getSheets()[0]; // Select the first sheet.
var cell = sheet.getRange(range); // Use supplied arguments
cell.setFontLine("line-through"); // set strikethrough
}
You can call this method like this (this will set the line style of the given range to 'line-through'):
// specify the range
setStrikethrough("B2:C4");
See https://developers.google.com/apps-script/reference/spreadsheet/

Related

How to add a button inside message body in Javascript?

I have tried constructing message body like below-
i am getting object object exception and it isn't working for me if i keep inside message body-
"Dear " +
$scope.emailContactinfo.name +
", \n\nPlease find attached Invoice bearing number " +
$scope.invoiceInformation.documentNo +"Paynow\n\n" +$scope.generatedUrl +
" dated " +
moment($scope.invoiceInformation.invoiceDate).format("MM-DD-YYYY") +
". \n\nThanks and Regards,\n" +
$scope.invoiceInformation.organization$_identifier +
"." + button ;`
I suggest using this format, so the code is more readable -
const button = '<button>Button</button>';
`Dear ${$scope.emailContactinfo.name}, \n\nPlease find attached Invoice bearing number ${$scope.invoiceInformation.documentNo} Paynow\n\n ${$scope.generatedUrl} dated ${ moment($scope.invoiceInformation.invoiceDate).format("MM-DD-YYYY")}. \n\nThanks and Regards,\n ${$scope.invoiceInformation.organization$_identifier}. ${button}`
You could use html in a javascript variable like this e.g.:
var button = '<button>Button</button>';
var htmlBody = '<div>' + $scope.emailContactInfo + '</div>;
htmlBody += '<div>' + button + '</div>';

How do I add social media icons to my code?

This is the code i have so far.
At the end of the email, I would like to provide social icons like these ones that i found free online. And to lead them to corresponding links i have. Minus the skype.
https://codepen.io/anon/pen/QgjeXw
function sendEmails() {
var allData,counter,emailAddress,fourRowsOfData,i,lastRow,
message,messageStart,messageEnd,numRows,
row,sheet,startRow,studentName,subject;
//USER INPUT
startRow = 2; // First row of data to process
numRows = 4; // Number of rows to process
subject = "Camp Pursuit: Report Card ";
messageStart = "Dear Parents,"+'\n' +'\n' +
"Every week at Camp Pursuit, we ask the teachers to make observations about how the kiddos did." +'\n' +
"We know that one week isn't enough to truly know a child, so we call this our " +"Glows, Grows, & Apropos." +'\n' +
"Meaning..." + '\n' +'\n' +
"Glows: Positive things the teacher noticed" +'\n' +
"Grows: Areas for continued growth" +'\n' +
"Apropos: Ways to continue your son/daughter's enrichment" +'\n' +
"We hope you appreciate seeing what the teachers saw last week, and perhaps you can use some of"+'\n' +
"the recommendations for further enrichment this summer. Feel free to let us know your thoughts on the camp through our anonymous online survey."+'\n' +
"Your feedback helps us improve the experience for all kiddos! "+'\n' +
"Survey Link: https://docs.google.com/forms/d/1g4LvA9a8sdKECr1yvp5uOoPnvKACFm3HvbTBfvQGRyo/viewform?usp=send_form" +'\n' +
"We look forward to seeing your child at our programs throughout the year!" +'\n' +
"Sincerely, "+'\n' +
"The Camp Pursuit Team"
+'\n';
//END USER INPUT
sheet = SpreadsheetApp.getActiveSheet();
lastRow = sheet.getLastRow();
allData = sheet.getRange(startRow, 1, lastRow-startRow, 10);// Get All data first
counter = 0;
while (counter < lastRow-startRow) {
Logger.log('counter: ' + counter)
fourRowsOfData = sheet.getRange(startRow + counter, 1, numRows, 6).getValues();
emailAddress = fourRowsOfData[0][0]; // First column of first row
Logger.log('emailAddress: ' + emailAddress)
studentName = fourRowsOfData[0][1];
messageEnd = "";//Reset on every outer loop
for (i = 0; i < numRows; i++) {//loop numRows times - once for each row
row = fourRowsOfData[i];
messageEnd = messageEnd + '\n' +
"Class: " + row[2] + '\n' +'\n' +
"Glows: " + row[3]+ '\n' +
"Grows: " + row[4] +'\n' +
"Apropos: " + row[5] +'\n';
}
message = messageStart + "\n" + studentName + "\n" + messageEnd;
MailApp.sendEmail(emailAddress, subject, message);//Send the email outside of inner loop
counter+=numRows;//Increment counter by number of rows to process
}
}
I don't think you will be able to use examples from codepen as they involve lots of code (e.g. for displaying hover states, etc). However, you could save the buttons as images and store them in your Drive or elsewhere.
The next step is to get the blob for your image from external URL
var imageBlob = UrlFetchApp.fetch(yourImageUrl).getBlob();
or from Drive
var imageBlob = DriveApp.getFileById(yourFileId).getBlob();
Build the string for the html body of your email. Use 'br' tags for line breaks. Wrap your images in 'a' tags to get them to link to external websites. In 'src' attribute of the 'img' tag, create a unique id for your image blob and put it after 'cid'.
var body = "<h1> Header </h1> <br />" +
"<a href='www.example.com'><img src='cid:uid' /></a> Image <br />" +
"Content";
Instead of string parameters, pass the following object to MailApp.sendEmail() method. At runtime, the script will parse the string stored in 'body' variable and create html output, using cid identifiers to retrieve images from inlineImages object. The property names of 'inlineImages' object must match the ids you put created for your images in 'body'
MailApp.sendEmail({
to: "recipient#example.com",
subject: "subject",
htmlBody: body,
inlineImages: {
uid: imageBlob
}
});
Concatenating the string to produce html body is not the best solution though. Consider creating a reusable html template using HtmlService https://developers.google.com/apps-script/guides/html/

jQuery append implementation is breaking

So I have this code that I am trying to alter –
Original:
jQuery(document).ready(function() {
var name = '';
var firstLastName = '[[T6:[[E48:[[S334:fr-id]]-[[S334:px]]:cons.first_name]]]] [[T6:[[E48:[[S334:fr-id]]-[[S334:px]]:cons.last_name]]]]';
var screenname = '[[T6:[[S48:0:screenname]]]]';
if (screenname) {
name = screenname;
} else {
name = firstLastName;
}
var splitName = name.split('');
var nameCheck = splitName[splitName.length-1];
jQuery('#personal_page_header h2').html("Support " + name + "'s Fundraiser" );
});
someone wrote this up and are no longer here, and what I'm trying to do now is figure out how to instead of replace the existing text, add to it.
So right now what this code does is it replaces the h2 content with the constituents registered name, or screenname.
What I'm trying to do now is append to that so that it will say something like
<h2>
Welcome to my fundraiser
<br/>
"Support" + name + "'s Fundraiser"
</h2>
but unfortunately what I tried breaks the code and stops it from working.
what I tried to do is this:
jQuery('#personal_page_header h2').append('<span><br />"Support " + name + "'s Fundraiser"</span>' );
I've tried to do a variety of other things that gave the same unsuccessful result.
Any help would be really appreciated!
Thanks
This should work for you:
jQuery('#personal_page_header h2').append("<span><br/>Support " + name + "'s Fundraiser</span>");
You've just got your quotations a little out of place.
You need to concatenate your code correctly, so if you'd like to keep the " use ' to concatenate. Further you need to escape the ' inside the string with \:
jQuery('#personal_page_header h2')
.append('<span><br />"Support ' + name + '\'s Fundraiser"</span>');

PL/SQL CHR(13)||CHR(10) returning 0

I'm using the EMail function in PL/SQL.
The function getting called by Javascript after button got clicked.
This working very fine.
My Problem is that I generate the EMail Body in Javascript using PL/SQL variables.
Code Looks like
var content = "Hello " + '|| chr(13)||chr(10)||' + " " + " Name: " + "'||v_name ||'" + '||chr(13)||chr(10) ||' + " ";
So here the problem chr(13)||chr(10) returning the character 0 in the string.
But i want a Newline.
I tried with \r\n which didn't worked.
HTML-Tags also don't work because my Email Provider giving me th HTML-Tags out.
Excuse my english :)
Hope someone can help me.
I tried with the '\r\n' in javascript and it worked for me.
var content = "Hello " + '\r\n' + " " + " Name: " + "'||v_name ||'" + '\r\n' + " Test";
alert(content);
below is the sample jsfiddle for the same.
https://jsfiddle.net/njbjusmk/.
I'm not sure yet, but you might've messed something up with your apostrophes.
Maybe you should try parsing your content as follows:
var content = "'Hello '||CHR(13)||CHR(10)||' Name: ||" + v_name + "'||CHR(13)||CHR(10)||' " + " Message body "+ "'";

Javascript Parameter Passing Not Working

The code dynamically creates a listview which works but i want to make it so when a listview item is clicked it sends the a url paramater to another method. When i set a paramater it doesnt alert the paramater, but when i give no parameter it works.
var output =
"<li onclick='openURL()'><h3> Module Code: " +
results.rows.item(i).module
+ "</h3>Room: "
+ results.rows.item(i).room +
"</li>";
The above works - No parameter in openURL();
var output =
"<li onclick='openURL('" + results.rows.item(i).url + "')'><h3> Module Code: " +
results.rows.item(i).module
+ "</h3>Room: "
+ results.rows.item(i).room +
"</li>";
The above doesnt work - I have done alert(results.rows.item(i).url) and it has a value.
function openURL(url) {
alert("opening url " + url);
}
Could someone explain what i'm doing wrong, i've been trying to solve the problem for hours.
Cheers!
You are using single quotes to open the HTML attribute, you can't use it as JavaScript String because you'll be closing the HTML attribute, use double quotes:
var output =
"<li onclick='openURL(\"" + results.rows.item(i).url + "\")'><h3> Module Code: " +
results.rows.item(i).module
+ "</h3>Room: "
+ results.rows.item(i).room +
"</li>";

Categories