File Listener – Read an external file and process it in Pega

Use case: Customer will load a CSV (Comma Separated file), Pega will read the file and save the data in a Data Type for further processing.

Demo Video:

What we have to create:

  1. Case Type: FileProcessing
  2. Data Type: CustomerData
  3. Service Package: CSVFilePackage
  4. Service-File rule: CSVServiceFile
  5. Parse Delimited rule: FileParseRuleCSV.CSV
  6. Activity: SaveDataActivity
  7. File Listener: CSVFileListener
  8. CSV File: TestData.csv

Create a Case Type

Create a Data type – CustomerData

Go to Records tab and configure the source – that is add the columns

CustomerNo, CustFName, CustLName, CustAddress

Go to Records tab and Make CustomerNo as primary key

Create a Page (CustomerPage) in the Work class

So basically this page points to the Data Type and hence it will get the reference of those properties.

Now lets Create the Service package (CSVFilePackage)

Give the Access Group – Requires Authentication uncheck it

Method section will be empty at the start after creation of the Service-File rule – method section will get populated or after creation of the Service-File Rule.

Now create the Service-File rule

Service tab

Method tab

Request tab

Parse segments:

Map to: Delemited ParseRule

Map to key: FileParseRuleCSV.CSV (parse rule should be with extension else it will create an error during runtime, After creation click the target icon and double check that the correct file is opening)

Activity: SaveDataActivity (Click the target icon and create a new activity)

Create ParseRule: Label=FileParseRuleCSV(don’t give .CSV)

Record Type = CSV (mandatory field) — then after creation ID will become FileParseRuleCSV.CSV

As the Record Type is CSV so the ID is FileParseRuleCSV.CSV

Now in the above screen short we are mapping the Clipboard properties.

.CustomerPage.CustomerNo

Now go to the activity

Now in the above screen short we are mapping the Clipboard properties.

.CustomerPage.CustomerNo

Now go to the activity

Create the activity to complete the Parse rule and save all the rules (Activity, Parse Delimited rule, Service rule)

Now check the Service Package, you will see the Method section got updated

Now lets write the activity

Go to Pages & Classes

Steps

Set the properties to the Page associated the CustomerData Data Type

Activity is read – Save it and other rules – Parse Rule and Service-File Rule

Now to test it manually we will run the Service-File rule (CSVServiceFile) and check if the data is inserting into the Data Type CustomerData or not.

Run the Service File rule –CSVSeriveFile

Provide the data

C001,F001,L001,A001

You will get the below screen

It is showing success

So go to the CustomerData Data Type — Check the data has been loaded in the records tab.

Now we are not going to insert data like this right? so we will have a file and will put it in a particular path and will read it from there with the help of a listener.

Click Create

File format “TestData.csv” (In notepad create a file with comma separated data and then Save the file as “TestData.csv”) keep it at ta location of your choice C:\<FolderName>\ (we shud end with ‘\’)

Source name mask: *.csv — that is file extension with csv will be accessed.

In this case I kept my “TestData.csv” file in a folder of my choice 🙂

Now fill up the Service package, Service Class, Service method

Process tab

Check Generate report file and Persist Log-Service-File instance

File operation – Keep or Delete — I have chosen Keep – You can choose Delete (by default).

Keep Default settings in the Error Tab

Now go to the Admin Studio –> Click Resources –> Listeners — Start / restart listener — Start new Instance — select CSVFileListener — Click Apply

Click Apply, Then you will see your listener in the Active Listeners list.

After creation of the listener you can check the CustomerData Data Type and refresh it to check if the data has been populated or not. It should get populated.

If not then,

So once you put the “TestData.csv” file in the C:\<YourFolder>\ location then you run the listener and refresh it in Admin Studio.

So the data has been processed and saved in the CustomerData Data Type.

This is the end of this POC. Hope you liked it and able to do it by yourself. 🙂

Please let me know your inputs.

2 Comments

  1. Hi , I am fan of your blog .
    Is there anyway I can chat with you personally like a gmail if please ? Looking forward for your response .