Expand my Community achievements bar.

SOLVED

Verify e-mail address field is not null.

Avatar

Level 9

I am trying to get the script below to verify the "ReleasedIntoSystemBy" field (drop-down with email address values) is not blank. What have I got wrong?

// Declare the variable
var vEmail;
var vSubject = "New Work Order/Project Authorization"
var vBody = "Instructions:"

// Check that the email field is not null
if (xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIntoSystemBy").rawValue !== null) {
     vEmail = xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIntoSystemBy").rawValue;
}

// Send email
event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=" + vSubject + "&body=" + vBody,cSubmitAs:"PDF",cCharset:"utf-8"});

1 Accepted Solution

Avatar

Correct answer by
Level 2

Here you go


// Declare the variable
var vEmail;
var vSubject = "New Work Order/Project Authorization"
var vBody = "Instructions:"

// Check that the email field is not null
if (xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIn toSystemBy").rawValue !== null) {
     vEmail = xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedInt oSystemBy").rawValue;
     // Send email
event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=" + vSubject + "&body=" + vBody,cSubmitAs:"PDF",cCharset:"utf-8"});
}else{
//displays message box warning user to fill in field

xfa.host.messageBox("Please fill the email field");

//sets the focus to the field
xfa.host.setFocus(xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIntoSystemBy"));

}

View solution in original post

8 Replies

Avatar

Level 2

The script looks correct however, you are doing //Send Email script whether or not the vEmail value is null as it lies outside the if statement

I''m assuming you want to send if vEmail is not null.  If that is the case then place the //Send Email script within the if statement.

Avatar

Level 9

Yes - you are correct. I did as you suggested and changed it as seen below. Now it does nothing when blank. Is it possible to generate a message telling the user they left that field blank?

// Declare the variable
var vEmail;
var vSubject = "New Work Order/Project Authorization"
var vBody = "Instructions:"

// Check that the email field is not null
if (xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIntoSystemBy").rawValue !== null) {
     vEmail = xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIntoSystemBy").rawValue;
     // Send email
event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=" + vSubject + "&body=" + vBody,cSubmitAs:"PDF",cCharset:"utf-8"});
}

Avatar

Correct answer by
Level 2

Here you go


// Declare the variable
var vEmail;
var vSubject = "New Work Order/Project Authorization"
var vBody = "Instructions:"

// Check that the email field is not null
if (xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIn toSystemBy").rawValue !== null) {
     vEmail = xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedInt oSystemBy").rawValue;
     // Send email
event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=" + vSubject + "&body=" + vBody,cSubmitAs:"PDF",cCharset:"utf-8"});
}else{
//displays message box warning user to fill in field

xfa.host.messageBox("Please fill the email field");

//sets the focus to the field
xfa.host.setFocus(xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIntoSystemBy"));

}

Avatar

Level 9

Is there a way to have the required fields verfied that they are populated before the custom email button executes?

Thanks again for your help!

Avatar

Level 2

if you execute the below script it will check all validations on the form such as required fields

 

xfa.form.form1.execValidate()   

form1 being the top node of you hierarchy

it will return a true or false, true if validatations are all fullfilled or false if not

In your script you could add an if statement similar to this

 

if(xfa.form.form1.execValidate() == true){

  //within here execute your above email script

}

Avatar

Level 9

Having trouble - is this correct?

var vEmail;
var vSubject = "New Work Order/Project Authorization"
var vBody = "Instructions:"

if(xfa.form.form1.execValidate() == true){

// Check that the email field is not null
if (xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIntoSystemBy").rawValue !== null) {
     vEmail = xfa.resolveNode("#subform[0].#subform[2].Table111[1].Row1.ReleasedIntoSystemBy").rawValue;
}

// Send email
event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=" + vSubject + "&body=" + vBody,cSubmitAs:"PDF",cCharset:"utf-8"});
}

Avatar

Level 9

I got it working - thanks again!