Expand my Community achievements bar.

Applications for the 2024-2025 Adobe Experience Manager Champion Program are open!
SOLVED

Customizing AEM Form Submissions for PDF/XML Formats

Avatar

Level 3

Hello Community Members,

 

I'm currently exploring the AEM form designer, and I find myself in need of some friendly advice.

 

Specifically, I'm curious about how to tailor the content of PDF or XML submissions when using the Submit or Email buttons. Is there a way to selectively exclude or render certain fields blank in the document sent via email? If yes, how can I do this?

 

Your kind insights and wisdom on this matter would be immensely appreciated.

 

Thank you all for being such a supportive community!

 

Update: Instead of using the email button, I made a regular button, and trying the below code (but nothing is happening)

 

 

 

function customSubmit() {
    // Get the form object
    var form = xfa.resolveNode("form1");

    // Get the values from the form fields within Subform_1
    var field1Value = form.Subform_1.TextField1.rawValue;
    var field2Value = form.Subform_1.TextField2.rawValue;

    // Construct the email body
    var emailBody = "Field 1: " + field1Value + "\n" +
                    "Field 2: " + field2Value;

    // Specify the email address and subject
    var emailTo = 'XYZ@example.com';
    var emailSubject = 'Subject';

    // Use the mailDoc method to send the email
    form.mailDoc({
        bUI: true,
        cTo: emailTo,
        cSubject: emailSubject,
        cMsg: emailBody,
        cSubmitAs: "PDF"
    });
}

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 3

0experience,

 

I see a few options:

1. When the form is completed and the user is ready to email the form you would need to include code that hides all other fields but the two you want to have visible. This would require having the form be totally dynamic with flowed subforms so that the two fields you want to have on the form will be at the top of one page not scattered across possible multiple pages.

 

2. Create a subform - either a page or regular subform that contains two fields that are just like the fields you want to have showing on the form when you email it. This subform would start as .access = "hidden"; when the form is first opened.

When the form is completed and the user is ready to email the form:

a. Include code to push the value of the two fields that were completed by the user to the two fields that are on the hidden subform. 

b. using the code: xfa.host.resetData("xfa.form."root node name"."page subform name".somExpression); remove all information from the fields that were completed by the user.

NOTE: "root node name" = the name of the root node which is the name at the very top of the Hierarchy. By default it is "form1" but some people change it.

"page subform name" = the name given to the first Page subform in the Hierarchy. By default this Page subform does not have a name. So it is a good idea to name it and use that name in this code.

c. Show the other subform with the two fields that now have values.

d. Email the form.

 

3. Your use case really calls for the use of AEM Forms. You would submit the form to a process or workflow, strip out the data, remove the data that is not required, then render the same form with the two fields of information. Then email the form to the appropriate email. However, you or your company or client would need to spend the money, time, etc. to get AEM Forms installed and working.

View solution in original post

6 Replies

Avatar

Level 10

The correct syntax for calling the mailDoc() method from a script in Designer is as follows:

 

event.target.mailDoc({
        bUI: true,
        cTo: emailTo,
        cSubject: emailSubject,
        cMsg: emailBody,
        cSubmitAs: "PDF"
    });

Avatar

Level 3

Thanks @radzmar for your response.

 

Now the code sends an email with a PDF attachment. The PDF contains all the fields from the form, but the email body only contains the two fields that I selected. However, I want the PDF to also only contain the two selected fields.

Avatar

Correct answer by
Level 3

0experience,

 

I see a few options:

1. When the form is completed and the user is ready to email the form you would need to include code that hides all other fields but the two you want to have visible. This would require having the form be totally dynamic with flowed subforms so that the two fields you want to have on the form will be at the top of one page not scattered across possible multiple pages.

 

2. Create a subform - either a page or regular subform that contains two fields that are just like the fields you want to have showing on the form when you email it. This subform would start as .access = "hidden"; when the form is first opened.

When the form is completed and the user is ready to email the form:

a. Include code to push the value of the two fields that were completed by the user to the two fields that are on the hidden subform. 

b. using the code: xfa.host.resetData("xfa.form."root node name"."page subform name".somExpression); remove all information from the fields that were completed by the user.

NOTE: "root node name" = the name of the root node which is the name at the very top of the Hierarchy. By default it is "form1" but some people change it.

"page subform name" = the name given to the first Page subform in the Hierarchy. By default this Page subform does not have a name. So it is a good idea to name it and use that name in this code.

c. Show the other subform with the two fields that now have values.

d. Email the form.

 

3. Your use case really calls for the use of AEM Forms. You would submit the form to a process or workflow, strip out the data, remove the data that is not required, then render the same form with the two fields of information. Then email the form to the appropriate email. However, you or your company or client would need to spend the money, time, etc. to get AEM Forms installed and working.

Avatar

Level 10

The following code won't work. 

 

 .access = "hidden";

 

 

It's either

 

.presence = "hidden"; // not visible

 

or

 

.access = "readOnly"; // write protected

 

depending on what you're after.

Avatar

Level 3

Very aware of that. I did not assume to put a full path.

I just put in the property. Assume that the user understands how to create the full path.