function sendEmails(e){
var UserName = e.values[3];
var UserEmail = e.values[5];
var date = e.values[0];
var pin = e.values[4];
var subject = "[LFR] Application Succeed!";
var bodymessage = "Hi" + UserName + "for sending in your job application."
<br>
<br> + "The following is your Purchase Log Pin"
<br> + pin;
var emailsent = "Email Sent";
var isEmailsent = e.values[6];
if (isEmailsent ! = emailsent);
MailApp.sendEmail(UserEmail, subject, bodymessage);
}
The error message always shows, "Illegally formed XML syntax. (line 18, file "Code"). Someone please help me to fix it!
change this
var bodymessage = "Hi" + UserName + "for sending in your job application."
<br>
<br> + "The following is your Purchase Log Pin"
<br> + pin;
to
var bodymessage = "Hi" + UserName + "for sending in your job application.<br> <br>The following is your Purchase Log Pin<br>" + pin;
bascially, your string is not formed correctly
Also,
remove ; after the if statement
if (isEmailsent ! = emailsent)
{
MailApp.sendEmail(UserEmail, subject, bodymessage);
}
Related
I have issues with the event time zone in my script. I browsed through many topics like this, but my beginner's skills did not allow me to transcribe the solutions to my own case ...
Here's my script:
function book1() {
var form = FormApp.getActiveForm();
var responses = form.getResponses();
var len = responses.length;
var last = len - 1;
var items = responses[last].getItemResponses();
var email = responses[last].getRespondentEmail();
var equipment = items[1].getResponse();
var datestart = items[2].getResponse();
var dateend = items[3].getResponse();
var cal = CalendarApp.getCalendarsByName(equipment)[0];
Logger.log(datestart);
Logger.log(dateend);
var start = new Date(datestart);
var end = new Date(dateend);
Logger.log('start '+start);
Logger.log('end '+end);
var allEvents = CalendarApp.getCalendarsByName(equipment)[0].getEvents(start, end);
if (allEvents.length < 1) {
var event = cal.createEvent(equipment, start, end)
.addGuest(email);
MailApp.sendEmail({
to: email,
subject: "Equipment " +equipment+ " booking confirmed",
htmlBody: "Equipment " +equipment+ " available, please return it by " +dateend+ " and scan the QR code when returning it.",
});
}
else {
var blob = HtmlService.createHtmlOutputFromFile("calendariframe").getBlob();
MailApp.sendEmail({
to: email,
subject: "Equipment " +equipment+ " not available",
htmlBody: blob.getDataAsString(),
});};
}
I can't find the right way to use getTimezoneOffset() or Utilities.formatDate in the right way. Would you have any advice on where to integrate them in my script so that the createEvent() works in GMT+1?
Thank you very much in advance for your help!
Solution found thanks to Cooper!
I went to the scripts project settings, checked the "Show "appsscript.json" manifest file in editor" box, went to the appsscript.json script and changed the timezone ID.
Essentially i'm also pulling email addresses from a separate sheet via a formula so that when new form entry is made, column B populates the proper email (name is included in the form). The problem I'm facing is that for the tool to be efficient I need to run the formula all the way down indefinitely so that when new entry comes it simply looks up the name and column B pulls the correct email address. However, the below code returns an error because it cannot handle #N/A where no email exists yet or even "" with IFERROR in the formula.
Ideally the code will stop if #N/A is encountered and only continues when there is an email in CurrentRow[1] has an email. The code works perfectly fine if empty rows are totally blank.
The current version here comes from what I've read and researched, including the post: Email only new rows in Google sheets. I've researched and lots of similar examples exist but having tried 40 or so variations i could not get mine to work.
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,11);
var AllValues = WholeRange.getValues();
var message = "";
//iterate loop
for (i in AllValues) {
//set current row
var CurrentRow = AllValues[i];
//define column to check if sent
var KamEmail = CurrentRow[1];
//if row has been sent, then continue to next iteration
if (CurrentRow[1] == "#N/A") {break;}
else;
//set HTML template for information
message +=
"<p>Hi " + CurrentRow[1] + "</p>" +
"<p>Your constituent has submitted an Agenda blog pitch" + "</p>" +
"<p><b>Name of constituent: </b>" + CurrentRow[2] + "</p>" +
"<p><b>Submission Snapshot: </b>" + CurrentRow[3] + "</p>" +
"<p><b>Link to Submission: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Date of Submission: </b>" + CurrentRow[7] + "</p><br><br>";
//set the row to look at
var setRow = parseInt(i) + StartRow;
//mark row as "sent"
ActiveSheet.getRange(setRow, 9).setValue("Sent to KAM");
}
//define who to send grants to
var SendTo = CurrentRow[1];
//set subject line
var Subject = "RE: Registrations";
//send the actual email
MailApp.sendEmail({
to: SendTo,
cc: "",
subject: Subject,
htmlBody: message,
});
}
Trying write javascript that prints "username=john01" and "password=password123" from the url below. Currently it prints nothing...
index.html?username=john01&password=password123<=_c1F9F2B16-96B3-9D7B-CC19-D22A43D4FCA1_kA54D6D0E-881B-2792-22D3-B857150B1EFC&_eventId=submit&submit=Sign+In
<html>
<body>
<p> This code is for educational purposes only, and is not to be used with malicious intent. </p>
<script>
string = window.location.search;
content = string.split("");
usernameStart = 1;
usernameEnd = content.indexOf("&",0);
username = content.substring(usernameStart,usernameEnd));
document.write("Your username is " + username);
</script>
</body>
</html>
var url = 'index.html?username=john01&password=password123<=_c1F9F2B16-96B3-9D7B-CC19-D22A43D4FCA1_kA54D6D0E';
var username = url.match(/username=([^&]*)/)[1];
var password = url.match(/password=([^&]*)/)[1];
document.getElementById('userinfo').innerHTML = 'Your username is ' + username + '<br/>And your password is ' + password;
You can try it directly on my JSFiddle
If you replace 'url' with 'window.location' and remove the first line, it should work from the url.
I am working on a task where the customer enters their contact information, and then all the details will appear on an alert box, I am facing a problem with converting a javascript code to JSON
<script type="text/language">
var
function getinfo() {
try{ var firstName =
document.myForm.firstName.value;
var LastName =
document.myForm.LastName.value;
FullName= firstName + LastName;
var Gender =
document.myForm.Gender.value;
var mail =
document.myForm.mail.value;
var Telephone =
document.myForm.Telephone.value;
var MobilePhone =
document.myForm.MobilePhone.value;
alert("FullName : "+FullName +"<br/> Mail: " + mail + "<br/>Telephone:" + Telphone +"<br/>Mobile: " + MobilePhone);
}catch(err){alert('Exception :: '+err)}
}
</script>
Your script has some errors:
it's document.forms.myForm and so on.
you didn't define "FullName" as a variable.
you use "Telphone" in the alertbox instead of "Telephone"
I've corrected them here:
<script type="text/language">
document.forms.myForm.elements.sub.onclick= function()
{
try{ var firstName = document.forms.myForm.firstName.value;
var LastName = document.forms.myForm.lastName.value;
var FullName= firstName + LastName;
var Gender =document.forms.myForm.Gender.value;
var mail = document.forms.myForm.mail.value;
var Telephone = document.forms.myForm.Telephone.value;
var MobilePhone =document.forms.myForm.MobilePhone.value;
alert("FullName : "+FullName +"<br/> Mail: " + mail + "<br/>Telephone:" + Telephone +"<br/>Mobile: " + MobilePhone);
}catch(err){alert('Exception :: '+err)}
}
</script>
But your script hasn't got to do anything with converting something to JSON.
You might use JSON.stringify() to "JSONify" your variables.
I'm working to expand on the workflow script posted here:
James Ferreira Workflow video.
function sendEmail(e) {
var email = e.values[1];
var Item = e.values[2];
var cost = e.values[3];
var vendor = e.values[4];
var url = '<SPREADSHEET>';
var approve = url + '?approval=true'+'&reply='+email;
var reject = url + '?approval=false'+'&reply='+email;
var html = "<body>"+
"<h3>Please review</h3><br />"+
Item +": " + cost+ ": " + vendor+ "<br />"+
"Approve<br />"+
"Reject<br />"+
"</body>";
MailApp.sendEmail("<MY EMIAL>", "Approval Request",
"What no html?", {htmlBody: html});
}
function doGet(e){
var answer = (e.parameter.approval == 'true') ? 'Buy it!' : 'Not this time, Keep saving';
MailApp.sendEmail(e.parameter.reply, "Purchase Request",
"Your manager said: "+ answer);
var app = UiApp.createApplication();
app.add(app.createHTML('<h3>An email was sent to '+ e.parameter.reply + ' saying: '+ answer + '</h3>'))
return app
}
Question 1) How do you build in an additional approval flow dependent on the cost?
Question 2) Depending on the approval amount how can I adjust the manager emaill?
For example: if the cost is above £500 I would like to send the approval email to another email account / manager. Would be amazing if the script could automatically recognise this.
Any support of this is much appreciated,
Andrew