Edit Content

Novitates Tech is committed to shaping a digital landscape that empowers businesses globally, offering accessible transformative solutions that ignite industry-wide change. Our dedication to innovation drives us to create strategies that redefine global business operations.

Get in touch

01. Overview

Problem Statement

In Pega Constellation, we have OOTB control to upload single/multiple excel files which will be attached to the case by default. However, if we want to parse the excel file and loop through the records to validate or display on the UI we should be using OOTB activity pxParseExcelFile.

However there is a gap/issue which is noticed out of this activity execution which throws pzUnrecognizedTemplate error which has to be handled manually with a couple of additional steps to implement this requirement.

02. Key Requirements

  1. OOTB Attachment Control to upload single/multiple records
  2. Using OOTB pxParseExcelFile activity to parse the uploaded content
  3. Validate records and display them on the UI

03. Solutions

Implemented a couple of additional steps before calling OOTB pxParseExcelFile activity for a smooth parsing of excel data without any issues.

Introduction

01. Background

Context of the requirement

In Theme-Cosmos world, we used to have the Upload File control for which we used to give the property reference as pxRequestor.pyFileUpload and use the same path to refer to the uploaded file in the service export directory. The uploaded files have to be manually processed and used for further usage.

In Constellation, we create a field with Type as “Attachment” where we provide the attachment category, whether it’s a single or multiple file upload. The uploaded file(s) is/are attached to the case automatically by pega once uploaded from the UI.

02. Objectives

  1. Upload single / multiple files to get them attached to the case and also view the attachment information stored on the attachment property.
  2. Should be able to parse the records in the uploaded excel and validate them according to the business requirements
  3. Should be able to save the records to a data type or to show them on the UI for review purposes.

03. Problem

What’s the gap/issue

When we try to use the pxParseExcelFile to parse the uploaded file, we face an error as shown below in tracer

(Code-Pega-List)pzUnrecognizedFileTemplate DonorTemplate

Implementation

01. Root cause Analysis

The root cause of this issue is that, in the pxParseExcelFile activity, pega is expecting the uploaded file to exist in the service export directory and if it does not find it, then it’s throwing this error.

In previous versions, once the file was uploaded, the uploaded file used to stay in the service export directory which enabled us to access it and use it.

Now, in Constellation, once the file is uploaded the excel file stream is read and committed to DB as an attachment, but the file does not exist on the service export directory in order to parse it further.

The error thrown is misleading as it talks about the excel template rule to be unrecognizable which is not true.

02. Approaches used to find the Issue

We have tried to add additional log categories to the below OOTB classes with DEBUG level and with that we were able to find out the real error behind the scenes.

  • com.pega.platform.pub.excel.ExcelUtils
  • com.pega.platform.pub.excel.ParseExcel

03. Implementation

As part of implementation, we need to follow below steps to ensure that this issue is resolved.

1. Take the attachment key of the attachment created in pega (Data-WorkAttach-File) from the primary page’s attachment embedded page.

Here I have used a single upload type of property.

2. Using the attachment key open the object and get the pyAttachStream out of it.

3. We need to recreate the uploaded file in the service export directory again using the pyAttachStream content.

Rather using a Java step you can write this into a function and ensure that below steps are implemented,

  1. Get the service export path
  2. Check if the directory exists, if it does not exist, make a new one.
  3. Replace all the spaces in the pyAttachStream content.
  4. Get the decoded byte array out of the encoded pyAttchStream content.
  5. Using outputstream write the byte array to the file path

Your export file path should look something like below

file://web:/StaticContent/global/ServiceExport/DonorContent.xlsx

4. Once the file is written in the service export directory, set up the Param.FSFileName and Param.TemplateRFB as usual and go ahead with the parsing. Ensure to check the bDeleteFile option so that after successful parsing the file which we created will be deleted by pega automatically.

5. Overall, your activity should look something below. Apart from the regular implementation only Step 3, 4 are additional here.

6. Once we are done with the parsing ParsePage.pxResults should have all the rows parsed and mapped. From here you can continue with your regular implementation validating the content, copying it to an embedded page list and showing up as a table on the UI as shown below.

Excel Template

Uploading excel on the case

Uploaded Excel File content

Displaying the records on the UI in the next screen after successful parsing.

Conclusion

01. Summary of Implementation

As part of this implementation we have understood the issue and fixed it gracefully with few additional steps.

  1. We have learnt that by using additional log categories and DEBUG levels, we can identify the actual root cause of any issue.
  2. We have understood how to write a file to service export file path using Pega OOTB classes and not using any custom java classes.
  3. We have also ensured that the files which we created are cleaned up properly after the parsing using OOTB option.

References

Pega Articles:

There were multiples based on this issue where we have tried to refer with no luck

https://support.pega.com/question/pzunrecognizedfiletemplate?

https://support.pega.com/question/cannot-read-file-upload

https://www.pegahelp.com/2020/06/how-to-read-excel-file-in-pega.html

Everywhere it was mentioned about the wrong template RFB and wrong path, but no where it was mentioned about the existence of the file in the so called  service export path.

Continue reading