I apologize. I am sure this is a rookie question, with a simple answer.
So I am using the following to send an email notification when a user creates an entry. Everything works fine, except two behaviors related to "null" (blank) entries.
function newSalesEmailMessage(sendButton) {
var pageWidgets = sendButton.root.descendants;
var fullName = app.datasources.CurrentUser.item.FullName;
var htmlbody = '<b><font size="3">' + fullName + '</font></b>' + ' has created a new sales entry for: ' +
'<h1><span style="color:#2196F3">' + pageWidgets.ShowName.value + '</h1>' +
'<p>Shoot Date: <b>' + pageWidgets.ProjectDate.value.toDateString() + '</b>' +
'<p>Contact: <b>' + pageWidgets.Contact.value + '</b>' +
'<p>Post AP: <b>' + pageWidgets.PostAP.value + '</b>' +
'<p>Sales Person: <b>' + pageWidgets.SalesPerson.value + '</b>' +
'<p>Notes: <b>' + pageWidgets.Notes.value + '</b>';
google.script.run
.withSuccessHandler(function() {
})
.withFailureHandler(function(err) {
console.error(JSON.stringify(err));
})
.sendEmailCreate(
'test#test.com',
'New Sales Entry for: ' + pageWidgets.ShowName.value,
htmlbody);
return sendButton === "" || sendButton === null || sendButton === undefined;
}
Issue 1: Whenever a user leaves a field blank the email puts "null" in the field, which makes sense, but people keep asking me "Who is null?" Ugh.
So if there is a way to output a blank space (ex:"") instead of "null" that would be great.
Issue 2: Whenever a user leaves the ProjectDate (which is a date field) blank I get the error: Cannot read property 'toDateString' of null.
This makes sense, but obviously this causes this script to not complete. I was hoping something like this would fix both issues, but it didn't:
function newSalesEmailMessage(sendButton) {
var pageWidgets = sendButton.root.descendants;
if (pageWidgets === null) {
pageWidgets = "";
}
var fullName = app.datasources.CurrentUser.item.FullName;
var htmlbody = '<b><font size="3">' + fullName + '</font></b>' + ' has created a new sales entry for: ' +
'<h1><span style="color:#2196F3">' + pageWidgets.ShowName.value + '</h1>' +
'<p>Shoot Date: <b>' + pageWidgets.ProjectDate.value.toDateString() + '</b>' +
'<p>Contact: <b>' + pageWidgets.Contact.value + '</b>' +
'<p>Post AP: <b>' + pageWidgets.PostAP.value + '</b>' +
'<p>Sales Person: <b>' + pageWidgets.SalesPerson.value + '</b>' +
'<p>Notes: <b>' + pageWidgets.Notes.value + '</b>';
google.script.run
.withSuccessHandler(function() {
})
.withFailureHandler(function(err) {
console.error(JSON.stringify(err));
})
.sendEmailCreate(
'test#test.com',
'New Sales Entry for: ' + pageWidgets.ShowName.value,
htmlbody);
}
Thank you for your help.
There are multiple ways to handle such situations, the easiest one will be introducing some helper functions:
// This function will return empty string in case widget's value is null
// You can return any default value or even pass it as function's parameter
function getSafeString(widget) {
return widget.value === null ?
'' :
widget.value;
}
function getSafeDate(widget) {
return widget.value === null ?
'' :
widget.value.toDateString();
}
function newSalesEmailMessage(sendButton) {
...
'...some HTML...' + getSafeString(widgets.SomeWidget) + '...some HTML...' +
'...some HTML...' + getSafeDate(widgets.DateWidget) + '...some HTML...'
...
}
By the way, I would also suggest using datasource.item (or datasource.modes.create.item, depending on your bindings), to get user inputs.
Related
I want to give last cell value of col no. 20 when mail has been sent with time and date in the below script. and using this code when more than one rows are added at a time then "sent" value is being added to the last row only and remaining rows are left blank. when new other row is added since value is not equal to sent those values are also been attached So, when mail sent complete column need to be given value as sent. Once please check this
function sendEmail() {
//setup function
var ActiveSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2");
var StartRow = 2;
var RowRange = ActiveSheet.getLastRow() - StartRow + 1;
var WholeRange = ActiveSheet.getRange(StartRow,1,RowRange,16);
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 (starts from "0" not "1")
var EmailSent = CurrentRow[14];
var caseworker = CurrentRow[7];
//if row has been sent, then continue to next iteration
if (EmailSent == "sent")
continue;
//set HTML template for information
message +=
"<p><b>Bank: </b>" + CurrentRow[1] + "</p>" +
"<p><b>Branch: </b>" + CurrentRow[2] + "</p>" +
"<p><b>Region: </b>" + CurrentRow[3] + "</p>" +
"<p><b>Lan Number: </b>" + CurrentRow[4] + "</p>" +
"<p><b>Customer Name: </b>" + CurrentRow[5] + "</p>" +
"<p><b>Loan Type: </b>" + CurrentRow[6] + "</p>" +
"<p><b>Case Worker: </b>" + CurrentRow[7] + "</p>" +
"<p><b>Site Visit Status: </b>" + CurrentRow[8] + "</p>" +
"<p><b>Site Visit Done By: </b>" + CurrentRow[9] + "</p>" +
"<p><b>Document recieved: </b>" + CurrentRow[11] + "</p>" +
"<p><b>File Upload: </b>" + CurrentRow[12] + "</p>" +
"<p><b>Remarks: </b>" + CurrentRow[10] + "</p><br><br>";
//set the row to look at
var setRow = parseInt(i) + StartRow;
//mark row as "sent"
ActiveSheet.getRange(setRow, 15).setValue("sent");
}
//define who to send grants to
var SendTo = "########gmail.com" + "," + "##########gmail.com" + "," + " ##########gmail.com";
//set subject line
var Subject = "New case initiated to Shirisha";
//send the actual email
MailApp.sendEmail({
to: SendTo,
cc: "##########gmail.com",
subject: Subject,
htmlBody: message,
});
}
I am using FullCalendar 3.5.1
My events are rendered through eventRender by injecting some links on the event data. These links works on Month view. But when I switch to Week or Day view, those links are un-clickable.
I have put a jsfiddle here https://jsfiddle.net/y8d0v6o3/1/
On the fiddle in month view throw console error but that is because not all functions are there on the fiddle but it also implies that links are getting clicked. On the Day/Week view there is not even an error.
eventRender: function(event, element, view) {
element.find(".fc-title").remove();
//element.find(".fc-time").remove();
$(element).css("margin-top", "3px");
$(element).addClass('event-on-' + event.start.format('YYYY-MM-DD'));
var wsTitleStyle = 'class="titlelinkConfirm"';
if(event.autoscheduled){
wsTitleStyle = 'class="titlelinkAutoSchd"';
}
if(event.missed){
//if missed change title color
wsTitleStyle = 'class="titlelinkMissed"';
}
var pbSurveyFlag = event.isSurvey ? 2 : 1;
if(event.title == 'ZZZZXXXYYY'){
event.eventBorderColor = '#FFF';
var wsMomentDate = event.start.format('YYYY-MM-DD');
var new_description ='<br/><a class="alink" href="javascript:calDetails('+ '''+'audits-appt-day.cfm' + '''+',500,400,' + '''+event.encryptedStart +''' +',' + '''+ 'dayView' + ''' + ','+'0' +')">'
+ 'Details' + '</a>' + ' '
+ '<a class="alink" href="javascript:calDetails('+ '''+'audits-mapDay.cfm' + '''+',800,600,' + '''+event.encryptedStart +''' +',' + '''+ 'dayView' + ''' +',' + ''' + wsMomentDate +''' +')">'
+ '<strong>Map Day</strong>' + '</a>'
;
element.append(new_description);
//do not allow this to be dragged
event.editable = false;
}else{
if (event.autoscheduled && !event.missed){
slink = '<a class="alink" href="javascript:doConfirmCal(' + '''+ event.auditID+'''+','+event.eventID+')">Confirm</a>';
} else if(!event.missed){
slink = '<a class="alink" href="javascript:popupReDirectEncryptedURL('+ '''+ 'auditID=' + event.auditID +'&missed='+ event.eventID +'&type=' + pbSurveyFlag+ '''+',' + '''+ 'ticket-progress.cfm' +''' + ',' + '800,500,'+ '''+'apptLetter' + '''+')">Missed</a>';
}
var new_description = '<a ' +wsTitleStyle+ ' href="javascript:LoadApptPage(' + event.eventID +',' + pbSurveyFlag +')">'
+ event.title + '</a><br/><br/>'
+ '<a class="alink" href="javascript:LoadFlexPage(' + ''' + event.auditID + ''' +',' + '''+pbSurveyFlag +''' +')">'
+ 'View' + '</a>' + ' '
+ slink
+ '<br/>' + ' ' + '<a class="alink" href="admin-timeTracking.cfm?isSurvey=' +pbSurveyFlag+'&auditID=' + event.auditID +'&date='+event.encryptedStart +'">'
+ 'Submit Time' + '</a>'
;
element.append(new_description);
}
}
I found that it was issue of z-index. Fullcalendar.css add z-index to it's css elements. So I added
postion:relative;
and a z-index high enough on my anchor tag css and that solved the issue.
I several weeks try to add button SMS Whatsapp and email in WP theme but I have errors.
window.open(link, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width='+winWidth+',height='+winHeight);
}
function eh_get_fburl(title, descr, url){
return 'http://www.facebook.com/share.php?u=' +encodeURIComponent(url)+ '&title=' + encodeURIComponent(title);
}
function eh_get_twurl(title, url){
return 'http://twitter.com/home?status=' + encodeURIComponent(title) + '+' + encodeURIComponent(url);
}
function eh_get_gpurl(url){
return 'https://plus.google.com/share?url=' + encodeURIComponent(url);
}
function eh_get_lnurl(title, url){
return 'http://www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
}
function eh_get_waurl(title, url){
return 'whatsapp CODE' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
}
function eh_get_txurl(title, url){
return 'SMS CODE' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
}
function eh_get_emurl(title, url){
return 'Email CODE" + title + "&body=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
}
for whatsapp:
return "whatsapp://send?text="+encodeURIComponent(url)+" "+encodeURIComponent(title)
for sms:
return "sms:my_phone_number?body="+encodeURIComponent(url)+" "+encodeURIComponent(title)
for email:
return "mailto:?subject="+encodeURIComponent(title)+ "&body="+encodeURIComponent(url)+" "+encodeURIComponent(title)
In this line:
var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&msg=' + msg;
What does the ampersand(&) mean?
I think the ampersands are meant for query string separation from each other
var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&msg=' + msg;
becomes
var dataString = 'name=John Doe&email=johndoe#gmail.com&subject=some email subject&msg=hey activate your account';
This can then be appended to your Url
var finalUrl = "http://mysite.com?" + dataString;
I have to insert values into database table wp_ratings table using ajax in wordpress but it is not working. Below is the code i am using:
Ajax call:
$(function(){
$('#submit').click(function(){
var rating_allowed=document.getElementById("rating_allowed").value;
var product_id=document.getElementById("product_id").value;
var user_id=document.getElementById("user_id").value;
var pc_ip=document.getElementById("pc_ip").value;
var performance_input=document.getElementById("performance_input").value;
var features_input=document.getElementById("features_input").value;
var battery_input=document.getElementById("battery_input").value;
var overall_input=document.getElementById("overall_input").value;
var rating_cat_count=document.getElementById("rating_cat_count").value;
var rate_1_name_find=document.getElementById("rate_1_name_find").value;
var rate_2_name_find=document.getElementById("rate_2_name_find").value;
var rate_3_name_find=document.getElementById("rate_3_name_find").value;
var rate_4_name_find=document.getElementById("rate_4_name_find").value;
var pros=document.getElementById("pros").value;
var cons=document.getElementById("cons").value;
alert("g");
alert("action=updateRating&product_id=" + product_id + "&user_id=" + user_id + "&pc_ip=" + pc_ip + "&performance_input=" + performance_input + "&features_input=" + features_input + "&battery_input=" + battery_input + "&overall_input=" + overall_input + "&rating_cat_count=" + rating_cat_count +"&rate_1_name_find=" + rate_1_name_find + "&rate_2_name_find=" + rate_2_name_find + "&rate_3_name_find=" + rate_3_name_find + "&rate_4_name_find=" + rate_4_name_find + "&pros=" + pros + "&cons=" + cons);
$.ajax({
url:"/wp-admin/admin-ajax.php",
type:'POST',
data:"action=updateRating&product_id=" + product_id + "&user_id=" + user_id + "&pc_ip=" + pc_ip + "&performance_input=" + performance_input + "&features_input=" + features_input + "&battery_input=" + battery_input + "&overall_input=" + overall_input + "&rating_cat_count=" + rating_cat_count +"&rate_1_name_find=" + rate_1_name_find + "&rate_2_name_find=" + rate_2_name_find + "&rate_3_name_find=" + rate_3_name_find + "&rate_4_name_find=" + rate_4_name_find + "&pros=" + pros + "&cons=" + cons,
success:function(results)
{
alert(results);
}
});
}
);
});
in functions.php file:
function implement_ajax_updateRating()
{
$p_id = mysql_real_escape_string(htmlentities(trim($_POST['product_id'])));
$user_id = mysql_real_escape_string(htmlentities(trim($_POST['user_id'])));
$pc_ip = mysql_real_escape_string(htmlentities(trim($_POST['pc_ip'])));
$rate_1 = mysql_real_escape_string(htmlentities(trim($_POST['performance_input'])));
$rate_2 = mysql_real_escape_string(htmlentities(trim($_POST['features_input'])));
$rate_3 = mysql_real_escape_string(htmlentities(trim($_POST['battery_input'])));
$rate_4 = mysql_real_escape_string(htmlentities(trim($_POST['overall_input'])));
$rating_cat_numbers = mysql_real_escape_string(htmlentities(trim($_POST['rating_cat_count'])));
$rate_1_find = mysql_real_escape_string(htmlentities(trim($_POST['rate_1_name_find'])));
$rate_2_find = mysql_real_escape_string(htmlentities(trim($_POST['rate_2_name_find'])));
$rate_3_find = mysql_real_escape_string(htmlentities(trim($_POST['rate_3_name_find'])));
$rate_4_find = mysql_real_escape_string(htmlentities(trim($_POST['rate_4_name_find'])));
$pros = mysql_real_escape_string(htmlentities(trim($_POST['pros'])));
$cons = mysql_real_escape_string(htmlentities(trim($_POST['cons'])));
//add_post_meta('17', 'ff_value', "ff", true);
$rating_insert = mysql_query("INSERT INTO wp_rating (post_id, rating_1, rating_2,rating_3,rating_4,user_id,comment_id,pc_ip,pros,cons)
VALUES (".$p_id.", ".$rate_1.", ".$rate_2.",".$rate_3.",".$rate_4.",".$user_id.",".$comment_id.",'".$pc_ip."','".$pros."','".$cons."')");
//$multi_in = multiRatingWidth($p_id, $rating_cat_numbers, $rate_1_find, $rate_2_find, $rate_3_find, $rate_4_find);
die();
}
add_action('wp_ajax_updateRating', 'implement_ajax_updateRating');
add_action('wp_ajax_nopriv_updateRating', 'implement_ajax_updateRating');
But alert is returning -1 & nothing is saved in database.