Expand my Community achievements bar.

SOLVED

How to call a custom written Form Data model PREFILL service to Interactive Communication Print channel?

Avatar

Level 3

We have to use two different API's data to one ICC letter. Created one FDM using these 2 sources with different services. Using a backend service created one JSON file the necessary data. Now how to attach this JSON file to this Print Channel.

 

Gone through the examples given in the experience league and other sites as well.

Generating Print Channel Document by Merging Data | Adobe Experience Manager

 

It says something like this in one of the example project 

dataOptions.setServiceName("ccm-print-test");

There is also classes created on this "ccm-print-test" service. But unable to load this example project into server to see if any bundle service created for this service class. 

 

Our request is to create get ICC letter that gets the dynamic data from the 2 different sources, and we created one FDM and attached that to the letter and  selected the Prefill Form Data Model service. Trying to send the JSON File data to this as given in the example class.  

 

Not sure how to link combined JSON to the letter. Here is the code; any suggestion will be apperciated.

 

String formName = "/content/forms/af/letter1/channels/print";
PrintChannel printChannel = null;
try {

JSONObject customerDetailJSONObject = new JSONObject();
String CustomerDetailsString=(IOUtils.toString(getClass().getResourceAsStream("/CustomerDetails.json"), StandardCharsets.UTF_8));
customerDetailJSONObject = new JSONObject(CustomerDetailsString);
InputStream targetStream = new ByteArrayInputStream(CustomerDetailsString.getBytes());
LOGGER.info("The size of target stream" + targetStream.available());
printChannel = this.printChannelService.getPrintChannel(formName);

PrintChannelRenderOptions options = new PrintChannelRenderOptions();
options.setMergeDataOnServer(true);
options.setRenderInteractive(false);
DataOptions dataOptions = new DataOptions();
dataOptions.setServiceName(printChannel.getPrefillService());
response.getWriter().println( "dataOptions.getServiceName()"+dataOptions.getServiceName()) ;

Resource icResource = this.getResolver.getFormsServiceResolver().getResource(formName);
dataOptions.setFormResource(icResource);



dataOptions.setServiceName("ccm-print-test");
dataOptions.setExtras(new HashMap<>());
dataOptions.getExtras().put("CustomerInformation", targetStream);
options.setDataOptions(dataOptions);


PrintDocument printDocument= printChannel.render(options);
new Document(printDocument.getInputStream());
InputStream fileInputStream = printDocument.getInputStream();
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=printICC.pdf");
response.setContentLength(fileInputStream.available());
OutputStream responseOutputStream = response.getOutputStream();
int bytes;
while ((bytes = fileInputStream.read()) != -1) {
responseOutputStream.write(bytes);
}
responseOutputStream.flush();
responseOutputStream.close();

} catch (Exception e) {
LOGGER.info("Exception " + e.getMessage());
e.printStackTrace();

}

 

 

 

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor
2 Replies

Avatar

Employee Advisor

Hi

If you need to get data from 2 different sources, you will have to write a wrapper service, fetch that data and use this wrapper service as the form data model for your IC. IC can only have one FDM.

 

Avatar

Correct answer by
Employee Advisor