Jump to content

JS to not include blank entries in notification email


Recommended Posts

Just tried this and it worked:

 

<script>
document.getElementById("Submit").onmouseover = function(){
var fname= document.getElementById("InsertRecordFirst_Name").value;
var lname = document.getElementById("InsertRecordLast_Name").value;
var age = document.getElementById("InsertRecordAge").value;
var desc = document.getElementById("InsertRecordDescription2").value;
var email="";
if (fname){
email=email +"\n" + "First Name= " + fname; 
}
if (lname){
email=email +"\n" + "Last Name= " + lname ; 
}
if (age){
email=email +"\n" + "Age= " + age ; 
}

if (desc ){
email=email +"\n" + "Description= " + desc ; 
}
document.getElementById("cbParamVirtual1").value = email;
}
</script>

There are 4 fields to check and a virtual field which is being used as email body.

Link to comment
Share on other sites

I set it up but its returning BLANK emails, no fields included.

I added the Virtual Field:

virtual1.png

I added the HTML block with the script (full script below)

virtual2.png

 

Called the Virtual1 field into email notification body:

virtual3.png

Completing forms (with some blanks), the notification email is completely empty when received.

 

Script used in HTML block:


<script>
document.getElementById("Submit").onmouseover = function(){
var Overnight= document.getElementById("InsertRecordOvernight").value;
var Tx = document.getElementById("InsertRecordTreated").value;
var No_tx = document.getElementById("InsertRecordReason_no_treat").value;
var NoTxO = document.getElementById("InsertRecordNo_tx_other").value;
var LVO = document.getElementById("InsertRecordLVO").value;
var Init = document.getElementById("InsertRecordPt_initials").value;
var Hosp = document.getElementById("InsertRecordHospital").value;
var HspO = document.getElementById("InsertRecordHosp_other").value;
var Age = document.getElementById("InsertRecordAge).value;
var Sex = document.getElementById("InsertRecordGender").value;
var LSN = document.getElementById("InsertRecordLSN_time").value;
var LSNtime = document.getElementById("InsertRecordSpecific_LSN").value;
var NIHSS = document.getElementById("InsertRecordNIHSS").value;
var Eval = document.getElementById("InsertRecordEval_method").value;
var Glu = document.getElementById("InsertRecordGlucose").value;
var Interv = document.getElementById("InsertRecordIntervention").value;
var DTG = document.getElementById("InsertRecordDTG_time").value;
var DTN = document.getElementById("InsertRecordDTN_time").value;
var Xfer = document.getElementById("InsertTransfer_UCMC").value;
var Enroll = document.getElementById("InsertRecordEnrolled").value;
var No_enroll = document.getElementById("InsertRecordReason_no_enroll").value;
var MD = document.getElementById("InsertRecordMD_initials").value;
var Comments = document.getElementById("InsertRecordComments").value;


var email="";
if (Overnight){
email=email +"\n" + "O/N= " + Overnight; 
}
if (Tx){
email=email +"\n" + "Tx= " + Tx; 
}
if (No_tx){
email=email +"\n" + "No_tx= " + No_tx; 
}

if (LVO){
email=email +"\n" + "LVO= " + LVO; 
}

if (Init){
email=email +"\n" + "Init= " + Init; 
}

if (Hosp){
email=email +"\n" + "Hosp= " + Hosp; 
}

if (HspO){
email=email +"\n" + "HspO= " + HspO; 
}

if (Age){
email=email +"\n" + "Age= " + Age; 
}

if (Race){
email=email +"\n" + "Race= " + Race; 
}

if (Sex){
email=email +"\n" + "Sex= " + Sex; 
}

if (LSN){
email=email +"\n" + "LSN= " + LSN; 
}

if (LSNtime){
email=email +"\n" + "LSNtime= " + LSNtime; 
}

if (NIHSS){
email=email +"\n" + "NIHSS= " + NIHSS; 
}

if (Eval){
email=email +"\n" + "Eval= " + Eval; 
}

if (Glu){
email=email +"\n" + "Glu= " + Glu; 
}

if (Interv){
email=email +"\n" + "Interv= " + Interv; 
}

if (DTG){
email=email +"\n" + "DTG= " + DTG; 
}

if (DTN){
email=email +"\n" + "DTN= " + DTN; 
}

if (Xfer){
email=email +"\n" + "Xfer= " + Xfer; 
}

if (Enroll){
email=email +"\n" + "Enroll= " + Enroll; 
}

if (No_enroll){
email=email +"\n" + "No_enroll= " + No_enroll; 
}

if (Trial){
email=email +"\n" + "Trial= " + Trial; 
}

if (MD){
email=email +"\n" + "MD= " + MD; 
}

if (Comments){
email=email +"\n" + "Comments= " + Comments; 
}

document.getElementById("cbParamVirtual1").value = email;
}
</script>

Probably missing something basic.

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 months later...
  • 11 months later...
  • 1 month later...

Data not getting passed correctly.  Following the instructions I have:

New Text Field (64000) to receive the email body:

1.jpg.333cb2b6dc67ef27218822a2752f3954.jpg

Does the Script go in Header?  In header I have your script ending in: 

document.getElementById("cbParamVirtual5").value = email;
}
</script>

New virtual and email field, hidden, receiving the Virtual5 script parameter: 

2.jpg.e3eb870e5e47d027fc89ec8f00edae3f.jpg

3.jpg.b85fad9fe3a1b1b9b5e255f81cc2e5fa.jpg

Im getting blank notification emails.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...