How do I include form data in email to SUBMITTER? - forms

I am trying to include in the email notification to the submitter/user (person filling out the form) the form the data from the form that the put into the form.
I found this tutorial on including it in the email to myself as the owner of the form (http://www.labnol.org/internet/google-docs-email-form/20884/), and it works great, but I want to send that information to the person who filled out the form.
I have tried replacing this code:
var email = Session.getActiveUser().getEmail();
with this code:
var email = e.namedValues["Email Address"].toString();
That doesn't seem to be the trick. I double-checked the field name in the form/response spreadsheet, and it does match "Email Address." I also made that a required field in the form.
Could someone assist me with this?

you need to check the each column in iteration....
if the column is email - address column then you need to assign to email variable.
here you need to assign
for ( var keys in columns )
{
var key = columns[keys];
if(columns[keys] == "Email Address")
{
email = e.namedValues[key].toString();
}
if ( e.namedValues[key] && (e.namedValues[key] != "") )
{
message += key + ' :: '+ e.namedValues[key] + "\n\n";
}
}

Related

Script for Google sheets (auto email function)

Google Sheets Script
I need to generate an auto email reply when Column "A" is marked "Completed". The email address to send this to is in Column "I" and subject of the email needs to be data in Column "H" while the body of the email will be generic for all emails sent. This is all specific to each Row.
I have multiple scripts running, for hiding rows etc, but nothing this complex.
All data is sent in to spreadsheet from Google Forms, and will need to encompass all rows
Any help would be much appreciated.
I created a script for something similar to this, except it runs off of check boxes. You could easily edit this code to have the email recipient variable to point to a value in a column by adding a .getdisplayvalue
How I used it is basically just as a script trigger, so I wouldn't have it replace the "progress" column you have, but to add a column for them to check when they're done editing the row.
Side Note: This script purposefully sets the check box back to default after clicking "yes I want to send the email" on the alert, otherwise the script would continuously run.
Without seeing your Google Sheet or current code/this code inserted, I wouldn't be able to help you implement at all. Let me know if this helps.
/*
A function to:
* After clicking a checkbox, auto prompt a yes/no box
* Upon "yes", copies that row from the source sheet to a destination sheet
* send an e-mail based on that new row's data
I reccomend protecting the response sheet and hiding it, as well as protecting the check box column to give edit access to only those you want to be able to send e-mails.
NOTES:
*It is important that the headers on your source sheet match your destination sheet.
* You have to run the script from the editor first to accept permissions for the emailapp and driveapp
* you need to set up a project trigger (edit/current project triggers) for the source sheet, on spreadsheet, on edit.
*The email will come from the owner of the google sheet and owner of the script project. (the person who reviews and accepts permissions)
MAKE SURE you are the owner of the sheet, that you are putting the code into the editor, and that you're okay with the e-mail coming from and replying to your email address.
*/
function EmailNotification(e) {
var ui = SpreadsheetApp.getUi();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Assets'); //source sheet
var columnb = sheet.getRange('B:B'); //Column with check boxes
var columnbvalue = columnb.getValues();
var notifysheet = ss.getSheetByName('Responses'); //destination sheet
var data = [];
var rownum =[];
//Condition check in B:B (or check box column); If true copy the same row to data array
for (i=0; i<columnbvalue.length;i++) {
if (columnbvalue[i] == 'true') {
var columnb2 = sheet.getRange('B2:B');
columnb2.setValue('false');
// What you want to say in the pop up alert
var response = ui.alert('Hold Up!\n Are you sure you want to send an email to finance for this asset change?', ui.ButtonSet.YES_NO);
if (response == ui.Button.YES) {
data.push.apply(data,sheet.getRange(i+1,1,1,20).getValues());
//Copy matched ROW numbers to rownum
rownum.push(i);
//Copy data array to destination sheet
notifysheet.getRange(notifysheet.getLastRow()+1,1,data.length,data[0].length).setValues(data);
var activeRow = notifysheet.getLastRow();
var assetname = notifysheet.getRange(activeRow, 1).getDisplayValue(); // The number is the column number in the destination "responses" sheet that you want to include in the email
var owner = notifysheet.getRange(activeRow, 3).getDisplayValue();
var serial = notifysheet.getRange(activeRow, 9).getDisplayValue();
var podate = notifysheet.getRange(activeRow, 6).getDisplayValue();
var email = 'theiremail#gmail.com' //The email address in which you want to send the email notification to
var subject = 'Asset has changed department ownership!'
//Body of the email message, using HTML and the variables from above
var message =
'<br><br><div style="margin-left:40px;">Heads Up!</div>'
+'<br><br><div style="margin-left:40px;">An asset has changed department ownership.</div>'
+'<br><br><div style="margin-left:40px;"><h3 style="text-decoration: underline;">Asset Name:'+ assetname +'</h3></div>'
+'<div style="margin-left:40px;">New Departmet Owner: '+ owner +'</div><br>'
+'<div style="margin-left:40px;">Serial: '+ serial +'</div>'
+'<div style="margin-left:40px;">Purchase Date: '+ podate +'</div>'
+ '<br><br><div style="margin-left:40px;">ヽ(⌐■_■)ノ♪♬</div>';
MailApp.sendEmail(
email,
subject,
"",
{
htmlBody: message,
name: 'Sadie Stevens', //The name you want to email coming from. This will be in bold, while your e-mail address will be small in italics
});
}
}
}
}
Try it this:
function EmailNotification(e) {
var ui=SpreadsheetApp.getUi();
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheetByName('Assets');
var columnb=sheet.getRange(1,2,sheet.getLastRow());
var columnbvalue=columnb.getValues();
var notifysheet=ss.getSheetByName('Responses');
var data=[];
var rownum=[];
for (var i=0;i<columnbvalue.length;i++) {
if (columnbvalue[i] == 'true') {
var columnb2=sheet.getRange(2,2,sheet.getLastRow()-1);
columnb2.setValue('false');
var response=ui.alert('Hold Up!\n Are you sure you want to send an email to finance for this asset change?', ui.ButtonSet.YES_NO);
if (response==ui.Button.YES) {
data.push(sheet.getRange(i+1,1,1,20).getValues());
rownum.push(i);
notifysheet.getRange(notifysheet.getLastRow()+1,1,data.length,data[0].length).setValues(data);
var activeRow=notifysheet.getLastRow();
var assetname=notifysheet.getRange(activeRow, 1).getDisplayValue(); // The number is the column number in the destination "responses" sheet that you want to include in the email
var owner=notifysheet.getRange(activeRow, 3).getDisplayValue();
var serial=notifysheet.getRange(activeRow, 9).getDisplayValue();
var podate=notifysheet.getRange(activeRow, 6).getDisplayValue();
var email='theiremail#gmail.com' //The email address in which you want to send the email notification to
var subject='Asset has changed department ownership!'
var message =
'<br><br><div style="margin-left:40px;">Heads Up!</div>'
+'<br><br><div style="margin-left:40px;">An asset has changed department ownership.</div>'
+'<br><br><div style="margin-left:40px;"><h3 style="text-decoration: underline;">Asset Name:'+ assetname +'</h3></div>'
+'<div style="margin-left:40px;">New Departmet Owner: '+ owner +'</div><br>'
+'<div style="margin-left:40px;">Serial: '+ serial +'</div>'
+'<div style="margin-left:40px;">Purchase Date: '+ podate +'</div>'
+ '<br><br><div style="margin-left:40px;">ヽ(⌐■_■)ノ♪♬</div>';
MailApp.sendEmail(email,subject,"",{htmlBody: message,name: 'Sadie Stevens'});
}
}
}
}

Send email when any cell in column is changed to 'YES'

I have a spreadsheet with a Yes/No column (column AP) and I need to send an email notification whenever any value within that column is changed. I have worked out how to send one when a specific cell is changed:
function sendNotification(e) {
if("AP4" == e.range.getA1Notation()) {
if(e.value == "YES") {
//Define Notification Details
var recipients = "***********#gmail.com";
var subject = "Update"+e.range.getSheet().getName();
var body = "This cell has changed";
//Send the Email
MailApp.sendEmail(recipients, subject, body);
}
}
}
However, I need this to work for any cell within column AP.
I also then need to store other values with the changed row as variables to use within the email body. So for example, the product name is in column B, and I need to be able to access this name so that my message reads something like "Column AP has been changed to 'Yes' for " + productName. Any help would be received very gratefully.
Try this:
function sendNotification(e){
if(e.range.getColumn()==42 && e.value=='YES'){
var recipients = "***********#gmail.com";
var subject = "Update"+e.range.getSheet().getName();
var body = "This cell has changed";
var valColB=e.range.getSheet().getRange(e.range.getRow(),2).getValue();
MailApp.sendEmail(recipients, subject, body)
}
}

Google Sheet Notifications: Email out text from specific cell/s if sheet edited

Is it possible to send a notification when a sheet is updated which references a particular cell?
The cell I want to reference, let's say C15, is static and contains text.
So when a form is submitted/the spreadsheet is updated, an email will arrive that says "VA spreadsheet updated: Your value-added was significantly lower/higher than average this month." Taking this text from cell C15.
Thanks
Tardy
This code should take care of emailing you the details computed from the form.
/* Paste the below code in your spreadSheets Tools > ScriptEditor
Then setup trigger for on onFormSubmit in ScriptEditor
Resources > Current Project Triggers > Add New Triggers > from Spreadsheet > on Form Submit
Remember to change the "Your email ID here" to email ID you need the mail to send the email
*/
function emailMileage() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Update");
var userEmail = "your Email ID here"
var sendername = "Mileage App"
var subject = "Your Mileage:";
if(sheet != null){
// This combines the values from three cells in update sheet with a space
var message = sheet.getRange(1,1,3,1).getValues().join(" ");
} else {
var message = "Unable to find update Sheet!"
}
MailApp.sendEmail({
to: userEmail,
name: sendername,
subject: subject,
htmlBody: message
});
}

Script access to custom address field through addressbook

I am having trouble setting a text value in a custom field I added to the address form.
function fieldChanged_form(type, name) {
if (name == 'custentity_bsi_agycampus') {
var lnSeq = nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T');
if (lnSeq > 0) {
console.log("selected line " + lnSeq);
nlapiSelectLineItem('addressbook', lnSeq);
var agency_campus = nlapiGetFieldText('custentity_bsi_agycampus');
nlapiSetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd', agency_campus, true, true);
console.log('agency' + ',' + agency_campus);
}
nlapiCommitLineItem('addressbook');
console.log('after commit: '
+ nlapiGetCurrentLineItemValue('addressbook',
'custrecord_bsi_agy_div_bur_sd'));
}
}
This script(applied to the Customer Form under the custom code tab) will not set custrecord_bsi_agy_div_bur_sd with the text value from custentity_bsi_agycampus (a custom field in the customer form). However, if I change custrecord_bsi_agy_div_bur_sd to addr1 (a field that is a default in the address form), it works just like I'd like.
This leads me to wonder whether or not I can access my custom field in the address form through 'addressbook' like you can for all of the other address fields. Does anyone know the answer to that question or have an idea of how I can troubleshoot this issue?
I believe you need to work with addresses as subrecords. Play around with something patterned after this:
// {nlobjSubrecord} Get one of the addresses off the sublist
var subrecord = {};
nlapiSelectLineItem('addressbook', 1);
subrecord = nlapiEditCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
// Set the data on the subrecord
subrecord.setFieldValue('attention', 'Some Guy');
subrecord.setFieldValue('addr1', '1234 5th St');
subrecord.setFieldValue('addr2', 'Apt 234');
subrecord.setFieldValue('addrphone', '5558675309');
subrecord.setFieldValue('city', 'Scottsdale');
subrecord.setFieldValue('state', 'AZ');
subrecord.setFieldValue('country', 'US');
subrecord.setFieldValue('zip', '85260');
// Commit the subrecord to its parent before submitting the parent itself
subrecord.commit();

Send Email fields not rendering in Sitecore Web Forms For Marketers

I have an issue with the WFFM Send Email Message save action (Sitecore 6.5.0). I'm trying to send an email that includes the form placeholders from the "Insert Field" dropdown in the Send Email editor. Sometimes the fields will render correctly, but most times the email will include the placeholder text instead of the field's actual value.
For example, this is the email that is coming through:
First Name: [First Name]
Last Name: [Last Name]
Email: [Email Address]
Company Name: [Company Name]
Phone Number: [Phone Number]
I think it has to do with the Send Email editor using a rich text editor for the email template, but I've tried adjusting the message's HTML to no avail. This is what the markup looks like: (the <p> tags and labels used to be inline, but that didn't work either)
<p>First Name:
[<label id="{F49F9E49-626F-44DC-8921-023EE6D7948E}">First Name</label>]
</p>
<p>Last Name:
[<label id="{9CE3D48C-59A0-432F-B6F1-3AFD03687C94}">Last Name</label>]
</p>
<p>Email:
[<label id="{E382A37E-9DF5-4AFE-8780-17169E687805}">Email Address</label>]
</p>
<p>Company Name:
[<label id="{9C08AC2A-4128-47F8-A998-12309B381CCD}">Company Name</label>]
</p>
<p>Phone Number:
[<label id="{4B0C5FAC-A08A-4EF2-AD3E-2B7FDF25AFA7}">Phone Number</label>]
</p>
Does anyone know what could be going wrong?
I have encountered this issue before, but was using a custom email action. I managed to fix it by not using the deprecated methods in the SendMail class and instead using the
Sitecore.Form.Core.Pipelines.ProcessMessage namespace's ProcessMessage and ProcessMessageArgs classes.
My use case was a little more complicated than yours, as we were also attaching a PDF brochure to our message (which is why we were using the custom email action in the first place), but here is the code:
public class SendBrochureEmail : SendMail, ISaveAction, ISubmit
{
public new void Execute(ID formId, AdaptedResultList fields, params object[] data)
{
try
{
var formData = new NameValueCollection();
foreach (AdaptedControlResult acr in fields)
{
formData[acr.FieldName] = acr.Value;
}
var senderName = formData["Your Name"];
var emailTo = formData["Recipient Email"];
var recipientName = formData["Recipient Name"];
var documentTitle = formData["Document Title"];
if (documentTitle.IsNullOrEmpty())
{
documentTitle = String.Format("Documents_{0}", DateTime.Now.ToString("MMddyyyy"));
}
Subject = documentTitle;
if (!String.IsNullOrEmpty(emailTo))
{
BaseSession.FromName = senderName;
BaseSession.CatalogTitle = documentTitle;
BaseSession.ToName = recipientName;
var tempUploadPath = Sitecore.Configuration.Settings.GetSetting("TempPdfUploadPath");
var strPdfFilePath =
HttpContext.Current.Server.MapPath(tempUploadPath + Guid.NewGuid().ToString() + ".pdf");
//initialize object to hold WFFM mail/message arguments
var msgArgs = new ProcessMessageArgs(formId, fields, MessageType.Email);
var theDoc = PdfDocumentGenerator.BuildPdfDoc();
theDoc.Save(strPdfFilePath);
theDoc.Clear();
FileInfo fi = null;
FileStream stream = null;
if (File.Exists(strPdfFilePath))
{
fi = new FileInfo(strPdfFilePath);
stream = fi.OpenRead();
//attach the file with the name specified by the user
msgArgs.Attachments.Add(new Attachment(stream, documentTitle + ".pdf", "application/pdf"));
}
//get the email's "from" address setting
var fromEmail = String.Empty;
var fromEmailNode = Sitecore.Configuration.Factory.GetConfigNode(".//sc.variable[#name='fromEmail']");
if (fromEmailNode != null && fromEmailNode.Attributes != null)
{
fromEmail = fromEmailNode.Attributes["value"].Value;
}
//the body of the email, as configured in the "Edit" pane for the Save Action, in Sitecore
msgArgs.Mail.Append(base.Mail);
//The from address, with the sender's name (specified by the user) in the meta
msgArgs.From = senderName + "<" + fromEmail + ">";
msgArgs.Recipient = recipientName;
msgArgs.To.Append(emailTo);
msgArgs.Subject.Append(Subject);
msgArgs.Host = Sitecore.Configuration.Settings.MailServer;
msgArgs.Port = Sitecore.Configuration.Settings.MailServerPort;
msgArgs.IsBodyHtml = true;
//initialize the message using WFFM's built-in methods
var msg = new ProcessMessage();
msg.AddAttachments(msgArgs);
msg.BuildToFromRecipient(msgArgs);
//change links to be absolute instead of relative
msg.ExpandLinks(msgArgs);
msg.AddHostToItemLink(msgArgs);
msg.AddHostToMediaItem(msgArgs);
//replace the field tokens in the email body with the user-specified values
msg.ExpandTokens(msgArgs);
msg.SendEmail(msgArgs);
//no longer need the file or the stream - safe to close stream and delete delete it
if (fi != null && stream != null)
{
stream.Close();
fi.Delete();
}
}
else
{
Log.Error("Email To is empty", this);
throw new Exception("Email To is empty");
}
}
catch (Exception ex)
{
Log.Error("Test Failed.", ex, (object) ex);
throw;
}
finally
{
BrochureItems.BrochureItemIds = null;
}
}
public void Submit(ID formid, AdaptedResultList fields)
{
Execute(formid, fields);
}
public void OnLoad(bool isPostback, RenderFormArgs args)
{
}
}
It is very possible that the Email Action that WFFM ships with is using the deprecated methods, which could be your problem. I do not have time to look into it, but you can decompile the DLL and look to see what their Email Action is doing. Regardless, the above code should work out of the box, save for updating the fields to those that you are using and removing the code for attaching the PDF, should you choose to not have attachments.
Good luck, and happy coding :)
If you change a field on the form in any way (caption, name, type, etc) the link will change and you need to re-insert the placeholder and move it up to its location in your expected email. This is also true if you duplicate a form. You'll have to reinsert all the fields in the email or you will just get the outcome you show above.
Reinserting upon a change will ensure the value is collected!