Skip to main content
Known Participant
June 18, 2018
Answered

ADOBE JAVASCRIPTS

  • June 18, 2018
  • 4 replies
  • 2873 views

I currently have this script running :

var patternEmpty = /^\s*$/;

var strMissing = "";

if(patternEmpty.test(this.getField("1st
purchaser").value))

     strMissing =
"1st purchaser";

  { // All is ok,
submit the data

  1. console.println("All form data ok");

  }

if(strMissing.length)

{// Got an error

  1. app.alert("Please complete 1st Purchaser: " +
    strMissing);

}

NEED this

var cToAddr =
"
Pcardreceipts@ifas.ufl.edu";

var cCCAddr =
this.getField("Email").value;

var cSubLine = " P-CARD FORM SUBMITTED FOR PROCESSING";
  1. this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr,
    cSubject: cSubLine,});

I want to merge script below into the above script or should it be written as one script and if any recommendations would be appreciated....?

var cToAddr =
"
Pcardreceipts@ifas.ufl.edu";

var cCCAddr =
this.getField("Email").value;

var cSubLine = " P-CARD FORM SUBMITTED FOR PROCESSING";
var cBody = " Thank you for funding this purchase.\n" + "We Appreciate your support";
  1. this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr,
    cSubject: cSubLine, cMsg: cBody});
This topic has been closed for replies.
Correct answer try67

I don't see any difference. 


I'll give you a hint: JavaScript is case-sensitive...

4 replies

BarlaeDC
Community Expert
Community Expert
June 19, 2018

HI,

What are you using to send the mail? as it works on osx with the default mail app.

Regards

Malcolm

Known Participant
June 19, 2018

ah ha....  we use PC windows 10, exchange (outlook)  not Mac

Known Participant
July 6, 2018

Ok, as requested I am using original forum.....

I have copied and pasted the above script into the Mouseup JavaScript and the Onblur as well and it doesn't open an email window... If i create the Mouse up Submit a Form  and enter in the mailto:xxxxxx and then insert the java script the validation of the required field completes and if it is populated the email window opens but it is not recognizing the cc: Email field any suggestions?  I really all appreciate all of the responses to date.  Just haven't been able to get the results desired....

BarlaeDC
Community Expert
Community Expert
June 19, 2018

HI,

The code you have posted works as I would expect, if I fill in the "1st purchaser" field and enter an email address in the email field, then once I click the button, I get an email generated with the contents of the email field in the CC section.

If I don't fill in the "1st purchaser" field, I get a dialog that says I should, and then it creates the email anyway, not sure this is what you want to happen?

Regards

Malcolm

Known Participant
June 19, 2018

almost there....  If the 1st purchaser isn't filled in the error message should appear requiring the person to go back and enter in the info required and then and only then should the email open....

BarlaeDC
Community Expert
Community Expert
June 19, 2018

Hi,

In that case you just need to add an else to your if statement.

So you code will become

var patternEmpty = /^\s*$/;

var strMissing = "";

if(patternEmpty.test(this.getField("1st purchaser").value))

     strMissing = "1st purchaser";

   { // All is ok, submit the data

console.println("All form data ok");

  }

if(strMissing.length)

{// Got an error

app.alert("Please complete 1st Purchaser: " + strMissing);

}

else

{

var cToAddr = " Pcardreceipts@ifas.ufl.edu";

var cCCAddr = this.getField("Email").value;

var cSubLine = "P-CARD RECIEPT FORM SUBMITTED FOR PROCESSING ";

var cBody = "Thank you for submitting your form.\n" + "Save the mail attachment for your own records";

this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

}

 

  This means that you alert will be shown OR your mail will be created, not both.

Hope this helps

Malcolm

Legend
June 18, 2018

If you would like us to take a look please post the exact revised script, and look in the console: please copy and paste any errors.

Known Participant
June 18, 2018

var patternEmpty = /^\s*$/;

var strMissing = "";

if(patternEmpty.test(this.getField("1st purchaser").value))

     strMissing = "1st purchaser";

   { // All is ok, submit the data

console.println("All form data ok");

  }

if(strMissing.length)

{// Got an error

app.alert("Please complete 1st Purchaser: " + strMissing);

}

var cToAddr = " Pcardreceipts@ifas.ufl.edu";

var cCCAddr = this.getField("Email").value;

var cSubLine = "P-CARD RECIEPT FORM SUBMITTED FOR PROCESSING ";

var cBody = "Thank you for submitting your form.\n" + "Save the mail attachment for your own records";

this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

Legend
June 18, 2018

It can replace the corresponding lines in the original. The only difference is setting a message body.

Known Participant
June 18, 2018

attempted your recommendations with no success.  Here is what i am attempting to accomplish,  I need the form to email the originator, if the email field (not required) is populated upon the approver using the submit (ADMIN) button for processing.  This button has the JavaScript to validate the 1st purchaser field before it will permit the form to be submitted using the ADMIN button.   I want to ad the var cCCaddr = this.getField ("Email") . value;  in the existing script yet can seem to place it in the correct place....

to clarify, the admin button has the mailto action set to the To: address and includes a JavaScript to validate field "1st purchaser" before the form can be sent for processing...  I want to add the "Email" field as cc when populated upon selecting the ADMIN button for processing to the existing JavaScript.