I feel like this should be pretty simple, but I can't find anything about it. I want my message that pops up in a ui.alert window to bold certain words and split a string at ,
into new lines. Here is the code I have:
function send(){
var ui = SpreadsheetApp.getUi();
var bccSend = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('main_gen').getRange(2,2).getValue(); //value example is [email protected], [email protected]
var bccSendReplace = bccSend.toString().replace(/,/g,"<br>");
var response = ui.alert('You are about to send this to the following email address(es): \n\n' + bccSendReplace + '\n\n Click OK to send, otherwise, close this box or click Cancel to abort.', ui.ButtonSet.OK_CANCEL);
}
The bccSendReplace
is what I want to parse at commas into new lines. Instead, the code just replaces the comma with <br>
. I would also like all text within bccSendReplace
to be bold. Any ideas? Thanks!
var array1 = [{}]; var string1 = "A, B, C, D"; array1 = string1. split(","); The problem is based on this kind of coding for example in flash. The string1 will split all "," then transfers it to the array1 in this format ["A","B","C", "D"] .
Select the text you want to modify. To bold text, click the Bold text button or press Ctrl+B (Windows) or Command+B (Mac) on your keyboard. The text will change to bold.
alert(prompt, buttons)
in Class Ui.'You are about to send this to the following email address(es): \n\n' + bccSendReplace + '\n\n Click OK to send, otherwise, close this box or click Cancel to abort.'
to the bold type.alert(prompt, buttons)
in Class Ui. So as a workaround, how about using the custom dialog with the method of showModalDialog
in Class Ui?When your script is modified, it becomes as follows.
Please copy and paste the following script and run the function of send
. By this, a dialog is opened. When the ok button and the cancel button are clicked, clickOk()
and clickCancel()
are run, respectively.
function send(){
var ui = SpreadsheetApp.getUi();
var bccSend = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('main_gen').getRange(2,2).getValue();
var bccSendReplace = bccSend.toString().replace(/,/g,"<br>");
const str = 'You are about to send this to the following email address(es): \n\n' + bccSendReplace + '\n\n Click OK to send, otherwise, close this box or click Cancel to abort.';
const html = `
<b>${str}</b><br>
<input type="button" value="ok" onClick="google.script.run.withSuccessHandler(() => google.script.host.close()).clickOk()">
<input type="button" value="cancel" onClick="google.script.run.withSuccessHandler(() => google.script.host.close()).clickCancel()">
`;
ui.showModalDialog(HtmlService.createHtmlOutput(html), 'sample');
}
function clickOk() {
// do something;
}
function clickCancel() {
// do something;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With