Generating Interactive Communications Document for print channel using watch folder mechanism

Last update: 2023-12-04
  • Created for:
  • Intermediate

After you have designed and tested your print channel document, you will typically need to generate the document by making a making a REST call or generate print documents using watch folder mechanism.

This article explains the use case of generating print channel documents using watched folder mechanism.

When you drop a file into the watched folder, a script associated with watched folder gets executed. This script is explained in the article down below.

The file dropped into watched folder has the following structure. The code will generate statements for all the accountnumber(s) listed in the XML document.







The code listing below does the following :

Line 1 - Path to the InteractiveCommunicationsDocument

Lines 15-20: Get the list of accountnumbers from the XML document dropped into the watched folder

Lines 24 -25: Get the PrintChannelService and Print Channel associated with the document.

Line 30: Pass the accountnumber as the key element to the Form Data Model.

Lines 32-36: Set the Data Options for the Document that is to be generated.

Line 38: Render the document.

Lines 39-40 - Saves the generated document to the file system.

The REST endpoint of the Form Data Model expects an id as an input parameter. this id is mapped to a Request Attribute called accountnumber as shown in the screenshot below.


var interactiveCommunicationsDocument = "/content/forms/af/retirementstatementprint/channels/print/";
var saveLocation =  new"c:\\scrap\\loadtesting");


var inputMap = processorContext.getInputMap();
var entry = inputMap.entrySet().iterator().next();
var inputDocument = inputMap.get(entry.getKey());
var aemDemoListings = sling.getService(;
var resourceResolver = aemDemoListings.getServiceResolver();
var resourceResolverHelper = sling.getService(;
var dbFactory = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance();
var dBuilder = dbFactory.newDocumentBuilder();
var xmlDoc = dBuilder.parse(inputDocument.getInputStream());
var nList = xmlDoc.getElementsByTagName("accountnumber");
for(var i=0;i<nList.getLength();i++)
 var accountnumber = nList.item(i).getTextContent();
resourceResolverHelper.callWith(resourceResolver, {call: function()
   var printChannelService = sling.getService(;
   var printChannel = printChannelService.getPrintChannel(interactiveCommunicationsDocument);
   var options = new;
   var map = new;
    // Required Data Options
   var dataOptions = new;
    var printDocument = printChannel.render(options);
   var statement = new;


To test this on your local system please follow the following instructions:

  • Setup Tomcat as described in this article. Tomcat has the war file which generates the sample data.

  • Set up service aka system user as described in this article.
    Make sure this system user has read permissions on the following node. To give the permissions login to user admin and search for the system user “data” and give the read permissions on the following node by tabbing to the permissions tab

    • /content/dam/formsanddocuments
    • /content/dam/formsanddocuments-fdm
    • /content/forms/af
  • Import the following package(s) into AEM using the package manager. This package contains the following:

  • Sample Interactive Communications Document

  • Watched Folder Script

  • Data Source Configuration

  • Open the /etc/fd/watchfolder/scripts/PrintPDF.ecma file. Make sure the path to the interactiveCommunicationsDocument in line 1 is pointing to the correct document that you want to print

  • Modify the saveLocation as per your preference on Line 2

  • Create accountnumbers.xml file with the following content


  • Drop the accountnumbers.xml into the C:\RenderPrintChannel\input folder.

  • The generated PDF files are written to the saveLocation as specified in the ecma script.


If you plan to use this on a non-windows operating system, please navigate to

/etc/fd/watchfolder /config/PrintChannelDocument and change the folderPath as per your preference

On this page