Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Adding variable Value into Email Submit Button

Avatar

Former Community Member
Hi,



is it possible to dynamic add an variable Field Value, (text field value from the form) into the Email Subject Field of the Email Submit Button?



Another question is if it is possible to add the Email address?



regards

Johannes Lehninger
8 Replies

Avatar

Former Community Member
Are you emailing from the form or from a process step in a workflow process?

Avatar

Former Community Member
Ok there are a couple of ways to accomplish this. If you are using a MAPI client for email you can use an Acrobat/Reader api that interacts with the Mapi interface. To get access to it you can use this javascript code:



var oDoc = event.target; //This will return a doc object in Acrobat

oDoc.mailDoc(UI, To address, CC Address, BCC address, Subject, Message);



where UI is a boolean indicating whether to disply a UI or not (this is always true with newer versions of Reader/Acrobat - for security reasons), To Address is the address as a string of the recipient, CC address is the email address of the CC recipient, BCC address is the address of the blind CC recipient, Subject is a string representing the subject of the email, and message is a string representing the message body of the email. In all cases a field's value can be used as the string or in concatenation with other text in the string.



The other way to do this is by using the mailto protocol with a submit button. Put a button on your form and make it a submit button. In the submit URL you can use the mailto protocol to submit to. Put a bogus entry in so that the right structure is set up in the XFA template. Now when you have the info on the form you can access the submit URL programmatically by using this command:



xfa.resolveNode("emailButtonName.#event").submit.target = "mailto:emailaddress?subject=This is my subject?body=This is the body of the message";



Any parts of the mailto can be substituted with values from your fields (as we did above).



I have also included a reference to the mailto syntax:



http://www.ianr.unl.edu/internet/mailto.html



Hope that helps

Avatar

Former Community Member
thx

it works with the first solution but,



what is the correct syntax for the substitution when I want to use the subject from the form field?



xfa.resolveNode("send.#event").submit.target = "mailto:x@test.com?subject=Subject&body=test";

Avatar

Former Community Member
Assuming you are programming in JavaScript you would use:



xfa.resolveNode("send.#event").submit.target = "mailto:x@test.com?subject=This is the subject with some data from a field ..." + fieldname.rawValue + "&body=test";

Avatar

Former Community Member
thx, everything worked fine



one final question on this topic: is it possible to give the attachment a defined name (test.pdf) ? or is it only possible to name it with a random value (_17s162en1e55f2h2m.pdf) ?

Avatar

Former Community Member
The random value is the temp file that is created when you are running in preview mode. I do not think you will see that when you save the file as a PDF and run it like that. Bottom line is no you cannot adjust the file name....it is the name of the PDF that is being viewed.

Avatar

Level 1

Thank you so much for posting this. I modified the code for my purposes. Someone may find this helpful:

//Grab the email from the dropdown or textfield or whatever field

var cToAddr = this.getField("SelectEmailDropDownMenuName").value;

// Second, if needed add the client CC email addresses

var cCCAddr = "name1@email.com; name2@email.com";

// or grab cc dynamically bu uncommenting this line

//var cCCAddr = this.getField("SelectEmailAdressName").value;

// Now get the beneficiary email only if it is filled out

var cBenAddr = this.getField("AnotherEmailField").value;

if(cBenAddr != "")

cCCAddr += ";" + cBenAddr;

// Set the subject and body text for the email message

var cSubLine = "My Subject Line Form"

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

// Send the entire PDF as a file attachment on an email

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