I have a google-app-maker, and it show some row data table. Every time it's row clicked, it will go to a page. And on that page there is button for sending invoice information. So recipient is static.
Client Name : Name_of_Client
But I can not grab field Name_of_Client into Msg
OnClick Script :
/* var widgets = widget.parent.descendants; */
var to = "webmaster#domain.com";
var subject = "Invoice Report";
var msg = "Client Name widget.datasource.item.Client_Name";
/* widgets.EmailStatus.text = 'Sending email...'; */
SendEmail(to, subject, msg);
Client Script :
function clearEmailForm(){
}
function SendEmail(To, Subject, Msg){
var status = "sending";
google.script.run.withSuccessHandler(function(result) {
status.text = 'Email sent...';
clearEmailForm();
})
.SendEmail(To, Subject, Msg);
}
Server Script :
function SendEmail(to, subject, msg){
MailApp.sendEmail(to, subject , msg);
}
The widget reference should be outside the string:
var msg = "Client Name " + widget.datasource.item.Client_Name;
Sometimes widgets don't inherit the datasource as expected, so you may need to reference the page or page fragment by using parent or root.
var msg = "Client Name " + widget.root.datasource.item.Client_Name;
Related
I am trying to write a script, that automatically sends an email when the form is submitted. This is the code I wrote:
function autoEmail(e) {
var response = e.response;
var formResponses = response.getItemResponses();
var email = formResponses[1].getResponse();
var name = formResponses[2].getResponse();
var size = formResponses[3].getResponse();
var subject = "Confirmation";
var body = "Dear " + name + " your size is " + size;
MailApp.sendEmail(email, subject, body)
}
When I try to run this simple code, I get: TypeError: Cannot read property 'getResponse' of undefined
I am trying to make a form in google app maker. I've created a form. which has a "preview(save" button, It will create a new item and I have a field named "status". The default value of this field is "draft". In the next page I have a "sent email" button. This page won't create any new item. It'll send the email and if the email deliver is successful then it'll update the field of status from "draft" to "completed"
This is my client script
function sendMessage(to, subject, msg){
// some part is omitted
var status = app.popups.NotificationDialog.descendants.notificationText;
var success = app.datasources.ChangeSystem;
google.script.run
.withFailureHandler(function(error){
// success.Success = "draft"
status.text = error.message;
})
.withSuccessHandler(function(result){
status.text = 'sent';
success.Success = "completed";
clearEmailForm();
})
.sendEmailMessage(to, subject, msg);
}
and this is my email sent button function
var widgets = app.pages.Email.descendants;
var to;
var subject = widgets.systemName.value
var msg = "Description:\n\t\t" + widgets.Objective.value;
widgets.EmailStatus.text = 'Sending email...';
sendMessage(to, subject, msg);
So far I am successful to send the email also I have created and saved all fields. But the problem is after sending the email the "status" field doesn't update. It remains the same as default value "draft". my expected result is after pressing the send button it will update one of the existing fields.
After some additional thinking on this topic I think I found the problem. Here is some updated code assuming your send email button is the same inherited datasource as the field that you are trying to update.
var success = widget.datasource.item;
google.script.run
.withFailureHandler(function(error)
status.text = error.message;
success.Success = 'draft';
})
.withSuccessHandler(function(result) {
status.text = 'Email sent';
success.Success = 'completed';
clearEmailForm();
})
.sendEmailMessage(to,subject, msg);
I have selected a user name from dropdown list values are from Directory, I would like to get that user's email address from the directory, I have tried in this way but it didn't work, could someone please help.
Image
`\\ client script
function getEmailAddress(Name)
{
var Email = EmailAddress(Name);
return Email;
}
\\Server Script
function EmailAddress(Name)
{
var query = app.models.Directory.newQuery();
query.filters.PrimaryEmail._contains.substring(Name);
return query.run();
}`
I got an solution for this, when I choose a person name from dropdown this gives person's email address automatically into email address field.
//Widget binding
setEmailAddress(#widget, #widget.root.descendants.EmployeeName.value)
//Client script
function setEmailAddress(widget, Fullname)
{
google.script.run
.withSuccessHandler(function(result){
widget.value = result;
})
.withFailureHandler(function(error){
error = "unable to load user's mail id";
console.error(error);
}) .getEmailAddress(Fullname);
}
}
//Server script
function getEmailAddress(Fullname){
var directoryQuery = app.models.Directory.newQuery();
directoryQuery.filters.FullName._equals = Fullname;
var person = directoryQuery.run()[0];
return person.PrimaryEmail;
}
I have a asp.net MVC 3 web application, where in some page I am showing a bar chart.
Now user is asking a "mailto" kind of link in that page and on clicking of that link, email client should open, where TO, Subject & Body will fill automatically and the bar chart should appear in body.
I know there is limitation of "mailto", we can prepare body with simple text like below, but is there any workaround to put graph within email body?
Check Mail
The mailto protocol is pretty limited. You might need to send the email from your server.
using Microsoft.Office.Interop.Outlook;
public void Sendemail()
{
try
{
Application oApp = new Application();
MailItem oMsg = (MailItem)(oApp.CreateItem(OlItemType.olMailItem));
// Set HTMLBody.
const string emailSubject = "Auto Generated Email:Graph Screen Shot Update for";
const string sDisplayName = "MyAttachment";
const int iPosition = 50; //
const int iAttachType = (int)OlAttachmentType.olByValue;
string htmlStart = "<html><body><h5><Font Color=Purpel>Hi,<br/>Please Find below The screen shot as of " + DateTime.Now + "<br/></h5>";
string body = string.Empty;
Microsoft.Office.Interop.Outlook.Attachment oAttach = oMsg.Attachments.Add(#"c:\Apps\download.jpg", iAttachType, iPosition, sDisplayName);
body += "<img src=\"cid:" + oAttach.FileName + "\" /><br/>";
string wholeBody = htmlStart + body + "<h5><Font Color=Purpel>Note:Please check the graph.<br/>Regards,<br/>Md. Ajmal<br/><br/></h5></body></html>";
oMsg.HTMLBody = wholeBody;
// Set the subject.
oMsg.Subject = emailSubject;
//display
oMsg.Display(oMsg);
// Clean up.
oMsg = null;
oApp = null;
}
catch (System.Exception ex)
{
throw ex;
}
}
I am very new to Netsuite. I am trying to do encryption in Netsuite. It works when I add UserEvent Scripts beforeSubmit. But I wanted to decrypt the encrypted text in beforeLoad function. I am able to read the encrypted text and decrypt it successfully as well. But setting it back in the object fails and I see decrypted text in Netsuite UI. Any directions or help is appreciated.
thanks
// this function works
function beforeSubmit(type) {
var email = nlapiGetFieldValue('email');
var newEmail = 'LifeSpan.' + email;
nlapiSetFieldValue('email', newEmail );
nlapiLogExecution('DEBUG', 'Modified before Submit ' + email + ' to ' + newEmail);
}
// this printed "Modified before Submit customercare#abc.com to LifeSpan.customercare#abc.com"
// this function doesn't work; even though the correct value is printed correctly in the log
function beforeLoad(type, form, request) {
var email = nlapiGetFieldValue('email');
if(email.indexOf('SaaSSpan.') != -1) {
var newEmail = email.substring(9);
nlapiSetFieldValue('email', newEmail );
nlapiLogExecution('DEBUG', 'Modified before load ' + email + ' to ' + newEmail);
}
}
// this printed "Modified before load LifeSpan.customercare#abc.com to customercare#abc.com"...but I am still seeing LifeSpan.customercare#abc.com in the user interface
I will suggest you to try this code in a client script(PageInit and SaveRecord Events).
Works fine for me.
My Code :
function PageInit(type) {
try {
if (type == 'edit') {
var email = nlapiGetFieldValue('email');
if (email != null && email.indexOf('LifeSpan.') != -1) {
var newEmail = email.substring(9);
nlapiSetFieldValue('email', newEmail);
nlapiLogExecution('DEBUG', 'Modified before load ' + email + ' to ' + newEmail);
}
}
}
catch (err) {
nlapiLogExecution('ERROR', 'PageInit', err);
}}
function SaveRecord() {
try {
var email = nlapiGetFieldValue('email');
var newEmail = 'LifeSpan.' + email;
nlapiSetFieldValue('email', newEmail);
nlapiLogExecution('DEBUG', 'Modified before Submit ' + email + ' to ' + newEmail);
}
catch (err) {
nlapiLogExecution('ERROR', 'SaveRecord', err);
}
return true;}
nlapiSetFieldValue can be used in user event beforeLoad scripts to initialize field on new records or non-stored fields.