I am trying to see if i can send an email based on whether or not a value is between two different values. IE: If value is >200 and <239 trigger email.
function sendMaileditbt200239(e){
if (e.range.columnStart != 26 || e.value < 200 > 239) return;
const rData = e.source.getActiveSheet().getRange(e.range.rowStart,1,1,44).getValues();
let firstname = rData[0][3]; //row of first name
let lastname = rData[0][2]; //row of last name
let tbcid = rData[0][1]; //row of TEA ID number
let phnum = rData[0][4]; //row of TEA ID number
let now = new Date().toLocaleString("en-US");
let msg = "Status: BILLING Name: " + firstname + " " + lastname + " Tel:" + phnum + " TBC ID:
" + tbcid + " Approved at " + now + ".";
Logger.log(msg);
MailApp.sendEmail("email#email.com", "Greater Then 200 less than 249", msg);
}
function sendMaileditbt200239(e) {
if (e.range.columnStart == 26 && e.value > 200 && e.value < 239) {
const rData = e.source.getActiveSheet().getRange(e.range.rowStart, 1, 1, 5).getValues();
let firstname = rData[0][3]; //row of first name
let lastname = rData[0][2]; //row of last name
let tbcid = rData[0][1]; //row of TEA ID number
let phnum = rData[0][4]; //row of TEA ID number
let now = new Date().toLocaleString("en-US");
let msg = "Status: BILLING Name: " + firstname + " " + lastname + " Tel:" + phnum + " TBC ID:
" + tbcid + " Approved at " + now + ".";
Logger.log(msg);
MailApp.sendEmail("email#email.com", "Greater Then 200 less than 249", msg);
}
}
Related
I have a google sheet containing 4 columns; title, url, published date and email sent (in that exact order).
When new rows are added to the sheet i want to execute a google script that will look through the 'email sent' column to see if an email has been sent and if not send an email containing the new rows and update the associated row(s) with a yes.
My current code is only getting the first row and nothing else.
Thanks in advance,
Mark
(see my current code below)
function sendemail() {
//setup function
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,4);
var AllValues = WholeRange.getValues();
//iterate loop
for (i in AllValues) {
//set current row
var CurrentRow = AllValues[i];
//set subject line
var Subject = "New Content on IG.com";
//set HTML template for information
var message =
"<p><b>Title: </b>" + CurrentRow[1] + "</p>" +
"<p><b>Article: </b>" + CurrentRow[2] + "</p>" +
"<p><b>Published Date: </b>" + CurrentRow[3] + "</p>";
//define column to check if sent
var EmailSent = CurrentRow[4];
//define who to send grants to
var SendTo = "TEST#gmail.com";
//if row has not been sent, then...
if (EmailSent != "Yes") {
//set the row to look at
var setRow = parseInt(i) + StartRow;
//mark row as "sent"
ActiveSheet.getRange(setRow, 4).setValue("Yes");
//send the actual email
MailApp.sendEmail({
to: SendTo,
cc: "",
subject: Subject,
htmlBody: message,
});
}
}
}
Try this:
function sendemail() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getActiveSheet();
const sr = 2;
const rg = sh.getRange(sr, 1, sh.getLastRow() - sr + 1, 4);
const vs = rg.getValues();
vs.forEach((r, i) => {
let Subject = "New Content on IG.com";
let message =
"<p><b>Title: </b>" + r[0] + "</p>" +
"<p><b>Article: </b>" + r[1] + "</p>" +
"<p><b>Published Date: </b>" + r[2] + "</p>";
let EmailSent = r[3];
let SendTo = "TEST#gmail.com";
if (EmailSent != "Yes") {
sh.getRange(i + sr, 4).setValue("Yes");
MailApp.sendEmail({to: SendTo,cc: "",subject: Subject,htmlBody: message});
}
})
}
Test:
A
B
C
D
1
Title
url
date
Sent
2
t1
u1
d1
Yes
3
t1
u2
d2
Yes
4
t1
u3
d3
Yes
5
t1
u4
d4
Yes
6
t1
u5
d5
Yes
7
t1
u6
d6
Yes
8
t1
u7
d7
Yes
9
t1
u8
d8
Yes
10
t1
u9
d9
Yes
It turns then all to Yes
I'm stuck on a blackjack assignment. I cant figure out how to let the user say hitMe Y/N as many times as they want. I have the dealer side down.
let card = 0;
let total = 0;
let hitMe = true;
let dealer = 0;
//1st card
hitMe = prompt("Current total: " + total, "Take a card? Y/N");
// (hitMe == "Y"){hitMe = true;}
//se {hitMe = false;}
if(hitMe){
card = dealer = Math.ceil(11*Math.random()) + Math.ceil(11*Math.random());
total += card;
}
//final total
dealer = Math.ceil(11*Math.random()) + Math.ceil(11*Math.random()); //dealer always takes 2 cards
alert("Your hand is worth " + total + ". Dealer got " + dealer + ".");
Use an if statement and a while loop, like so:
let card = 0;
let total = 0;
let hitMe = true;
let dealer = 0;
hitMe = prompt("Current total: " + total, "Take a card? Y/N");
if(hitMe == "Y"){
while(hitMe == "Y"){
card = dealer = Math.ceil(11*Math.random()) + Math.ceil(11*Math.random());
total += card;
hitMe = prompt("Current total: " + total, "Take a card? Y/N");
}
} else {
dealer = Math.ceil(11*Math.random()) + Math.ceil(11*Math.random());
alert("Your hand is worth " + total + ". Dealer got " + dealer + ".");
}
If the user doesn't input a Y, the final total will display.
My current script is able to send an email, but it sends multiple email with one row of data in each email. I want the script to be able to send one email with all rows of data.
function tazEmail() {
var sheet = SpreadsheetApp.openById("1naSWINA8_uxeLUsj0lFntqILyDj2nirb56uvkBel79Y").getSheetByName("Sheet3");
//var ss = SpreadsheetApp.getActive().getSheetByName("CRM Feedback");
var data = sheet.getRange(2, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues();
var manager_email = "email#email.org.au";
for( var i = 1; i< data.length;i++ ) {
var timestamp = data[i][0];
var requesterEmail = data[i][1];
var starRating = data[i][2];
var requestCatergory = data[i][3];
var description = data[i][4];
var label = data[i][5];
var ticketId = data[i][6];
var comment = data[i][7];
var status = data[i][8];
var priority = data[i][9];
var office = data[i][10];
var message = "";
var check = data[i][11];
if (check == "complete"){
continue;
}else {
var subject = "CT IT feedback - ";
var body = "<body>";
message +=
"<p><b>Timestamp by: </b>" + data[i][0] + "</p>" +
"<p><b>Requester Email: </b>" + data[i][1] + "</p>" +
"<p><b>Star Rating: </b>" + data[i][2] + "</p>" +
"<p><b>Request Category: </b>" + data[i][3] + "</p>" +
"<p><b>Description: </b>" + data[i][4] + "</p>" +
"<p><b>Label: </b>" + data[i][5] + "</p>" +
"<p><b>Ticket ID: </b>" + data[i][6] + "</p>" +
"<p><b>Comment: </b>" + data[i][7] + "</p>" +
"<p><b>Status: </b>" + data[i][8] + "</p><br><br>";
MailApp.sendEmail({
to: manager_email,
subject: subject,
htmlBody: message,
});
}
}
}
Try:
function tazEmail() {
var sheet = SpreadsheetApp.openById("1naSWINA8_uxeLUsj0lFntqILyDj2nirb56uvkBel79Y").getSheetByName("Sheet3");
//var ss = SpreadsheetApp.getActive().getSheetByName("CRM Feedback");
var data = sheet.getRange(2, 1, sheet.getLastRow(), sheet.getLastColumn()).getValues();
var manager_email = "email#email.org.au";
var message = "";
var subject = "CT IT feedback - ";
var body = "<body>"; // Don't think this is being used. May be deleted.
for( var i = 1; i< data.length;i++ ) {
var timestamp = data[i][0];
var requesterEmail = data[i][1];
var starRating = data[i][2];
var requestCatergory = data[i][3];
var description = data[i][4];
var label = data[i][5];
var ticketId = data[i][6];
var comment = data[i][7];
var status = data[i][8];
var priority = data[i][9];
var office = data[i][10];
var check = data[i][11];
if (check == "complete"){
continue;
}else {
message +=
"<p><b>Timestamp by: </b>" + data[i][0] + "</p>" +
"<p><b>Requester Email: </b>" + data[i][1] + "</p>" +
"<p><b>Star Rating: </b>" + data[i][2] + "</p>" +
"<p><b>Request Category: </b>" + data[i][3] + "</p>" +
"<p><b>Description: </b>" + data[i][4] + "</p>" +
"<p><b>Label: </b>" + data[i][5] + "</p>" +
"<p><b>Ticket ID: </b>" + data[i][6] + "</p>" +
"<p><b>Comment: </b>" + data[i][7] + "</p>" +
"<p><b>Status: </b>" + data[i][8] + "</p><br><br>";
}
}
MailApp.sendEmail({
to: manager_email,
subject: subject,
htmlBody: message
});
}
I have successfully accessed a Google calendar event and can change the color, but I'm stuck when it comes to removing the hangouts link.
I'm attempting to use code to automatically remove the hangouts links when I am the meeting originator and have not changed the hangout name, but I'm not having any success in actually changing the link.
Any help greatly appreciated.
function removehangout() {
var calendarId = 'primary';
//var calendars = CalendarApp.getOwnedCalendarsByName('Mirage ELDRIDGE');
var now = new Date();
// Determines how many events are happening in the next 24 hours x 1 days.
var now = new Date();
var endr = new Date(now.getTime() + (1 * 24 * 60 * 60 * 1000));
var events2 = CalendarApp.getDefaultCalendar().getEvents(now, endr);
Logger.log('Number of events: ' + events2.length);
var events = Calendar.Events.list(calendarId, {
timeMin: now.toISOString(),
singleEvents: true,
orderBy: 'startTime',
maxResults: 5
});
if (events.items && events.items.length > 0) {
for (var i = 0; i < events.items.length; i++) {
var event1 = events.items[i];
var d = event1.description;
var ttitle = event1.summary;
var whoby = event1.creator.email;
Logger.log(ttitle + ' by: ' + whoby);
if(whoby.indexOf('mirage.eldridge') != -1){
Logger.log(ttitle + '--> was by mirage');
var hangoutname = event1.hangoutLink;
Logger.log(ttitle + '--> hangout link name --> ' + hangoutname);
if (hangoutname != null) {
if (hangoutname.indexOf('mirage-eldridge') != -1){
//delete this link here
Logger.log(ttitle + '--> remove hangout');
//event.setHangoutLink(null);
//var idno = event.iCalUID
//CalendarApp.getEventSeriesById(idno)
event1.HangoutLink = null;
Logger.log(ttitle + '... ' + event1.hangoutLink);
Logger.log(event1.iCalUID);
//event.setcolorId('11');
var event2 = Calendar.Events.get(calendarId, event1.id)
event2.colorId = 9;
event2.hangoutLink = 'fred';
//Calendar.Events.patch(event2,calendarId,event1.id);
Calendar.Events.update(event2,calendarId,event1.id);
}
} else {
Logger.log(ttitle + ' -- do not remove ' + hangoutname);
}
}
if (!d)
d = '';
//var foundlinkyes = d.indexOf('HangoutLink');
//var actuallink = event.hangoutLink;
//var hasrlink = 'True';
//if (!actuallink) {
//Logger.log(ttitle + ' no link found');
//hasrlink = "False";
//}
//Logger.log('desc: ' + ttitle + '-- foundyes: ' + foundlinkyes);
//if (foundlinkyes == -1 && hasrlink == 'True'){
//if (event.hangoutLink && (d.indexOf('Hangout: ')== -1)){
//Logger.log (event.summary + ' - ' + event.hangoutLink + ' - ' + event.description);
//Logger.log(ttitle + ' added this ' + event.hangoutLink);
//event.description = 'HangoutLink: ' + event.hangoutLink + '\n\n' + d;
//Calendar.Events.update(event, calendarId, event.id);
//foundlinkyes = 0;
//hasrlink = 'True';
//}
//}
}
} else {
Logger.log('No events found.');
}
}
I'm using Google Apps Script to iterate through my contacts and print name, address, email and phone numbers to a document.
I want the name in style "Heading 2" and the rest in style "Normal text".
How can I do this?
Here's what I've got so far but it makes the whole paragraph Heading 2, instead of just the name.
var myContacts = ContactsApp.findContactGroup('Some group').getContacts();
for (i=0; i < myContacts.length; i++)
{
var fullName = myContacts[i].getFullName();
if (fullName == '')
fullName = 'Anonymous';
var contactPara = doc.appendParagraph(fullName);
contactPara.setHeading(DocumentApp.ParagraphHeading.HEADING2);
var homeAddresses = myContacts[i].getAddresses(ContactsApp.Field.HOME_ADDRESS);
var homeAddress = '';
if (homeAddresses.length > 0)
contactPara.appendText('\n' + homeAddresses[0].getAddress());
contactPara.appendText('\n' + 'Email: ' + myContacts[i].getPrimaryEmail());
var mobilePhones = myContacts[i].getPhones(ContactsApp.Field.MOBILE_PHONE);
if (mobilePhones.length > 0)
contactPara.appendText('\n' + 'Mobile phone: ' + mobilePhones[0].getPhoneNumber());
var homePhones = myContacts[i].getPhones(ContactsApp.Field.HOME_PHONE);
if (homePhones.length > 0)
contactPara.appendText('\n' + 'Home phone: ' + homePhones[0].getPhoneNumber());
var workPhones = myContacts[i].getPhones(ContactsApp.Field.WORK_PHONE);
if (workPhones.length > 0)
contactPara.appendText('\n' + 'Work phone: ' + workPhones[0].getPhoneNumber());
}
Alternatively, if there's a better way to do what I want them please suggest it.
You initially set the style throughout the paragraph, and then add back the text.
You can create 2 section:
for the fullName
var headPara = doc.appendParagraph(fullName);
headPara.setHeading(DocumentApp.ParagraphHeading.HEADING2);
and new paragraph with normal style for content
var contactPara = doc.appendParagraph(' ').setHeading(DocumentApp.ParagraphHeading.NORMAL);
Result
var myContacts = ContactsApp.getContacts();
for (i=0; i < myContacts.length; i++)
{
var fullName = myContacts[i].getFullName();
if (fullName == '')
fullName = 'Anonymous';
var headPara = doc.appendParagraph(fullName);
headPara.setHeading(DocumentApp.ParagraphHeading.HEADING2);
var contactPara = doc.appendParagraph(' ').setHeading(DocumentApp.ParagraphHeading.NORMAL);
var homeAddresses = myContacts[i].getAddresses(ContactsApp.Field.HOME_ADDRESS);
var homeAddress = '';
if (homeAddresses.length > 0)
contactPara.appendText('\n' + homeAddresses[0].getAddress());
contactPara.appendText('\n' + 'Email: ' + myContacts[i].getPrimaryEmail());
var mobilePhones = myContacts[i].getPhones(ContactsApp.Field.MOBILE_PHONE);
if (mobilePhones.length > 0)
contactPara.appendText('\n' + 'Mobile phone: ' + mobilePhones[0].getPhoneNumber());
var homePhones = myContacts[i].getPhones(ContactsApp.Field.HOME_PHONE);
if (homePhones.length > 0)
contactPara.appendText('\n' + 'Home phone: ' + homePhones[0].getPhoneNumber());
var workPhones = myContacts[i].getPhones(ContactsApp.Field.WORK_PHONE);
if (workPhones.length > 0)
contactPara.appendText('\n' + 'Work phone: ' + workPhones[0].getPhoneNumber());
}