Skip to main content
Participant
September 3, 2025
Question

Combining two bits of JavaScript in mailto

  • September 3, 2025
  • 2 replies
  • 151 views

G'day,

 

I'm trying use the mailto function for a button that should rename the subject line to the name of the PDF and also take an email address that is written previously in the document as the recipient of the email.

 

This is what I'm working with;

var docName = this.documentFileName;

var mailtoUrl = "mailto:[Email address]?body=[custom body]&subject="+ encodeURIComponent(docName); this.submitForm({ cURL: mailtoUrl, cSubmitAs: "PDF" });

 

and 

 

getURL("mailto:" + getField("07 Work Email").value

 

Both of the bits of script work seperately but I have no idea to combine them.

 

2 replies

try67
Community Expert
Community Expert
September 3, 2025

The last command doesn't do what you're trying to do. It tries to convert the URL you provide to a PDF, which can't work with a "mailto" address. Your original code should work, but if you want to insert the value of a field into the string, do the following:

 

var mailtoUrl = "mailto:" + this.getField("07 Work Email").value + "?body=[custom body]&subject="+ encodeURIComponent(docName); 

 

Bernd Alheit
Community Expert
Community Expert
September 3, 2025

Check the Javascript console for errors (ctrl-j).