Updated: Feb 5, 2020
We use file services/ file listeners to read and process the data in files that were exported from another system or copied to a specific folder in a file repository. The file listener monitors the file directory and calls the file service whenever a files arrives. The file service might use a parse rule for XML, structured, or delimited data, or a JSON data transform to read the files and map the data into fields on the clipboard. A service activity will then process the data by creating a case using the available file data and also start a flow.
To configure the file service and file listener, we have to perform the following high-level tasks:
Creating the Parse Delimited rule
Creating the service activity
Creating the service package
Creating the service request processor for multi-threaded processing
Creating the service file rule
Creating the file listener
Creating the Parse Delimited rule:
The most common use case is to use a Parse Delimited rule to map properties to the fields in a .csv file. To configure the parse delimited rule the given steps has to be followed.
1. Create a case with required fields / properties.
2. In the Dev Studio header, click Create > Integration-Mapping > Parse Delimited.
3. In the Label field, enter a short description.
4. In the Record type field, enter a valid Java identifier value.
5. In the Apply to field, select the class to which this rule applies. Click Create and open.
6. In the Field format field, select the format of the incoming file.
7. In the Method field, configure how to process the file.
8. In the Parsing details section, define the property mapping.
9. Parsing is done from left to right and Click Save.
Creating the service activity:
We configure a service activity to configure the file service to perform an action on each record of the file, one record at a time. In addition to parsing the .csv file, the service activity typically creates a work object for each record.
1. In the Dev Studio header, click Create > Technical > Activity.
2. In the Label field, enter a short description. In the Apply to field, select the class to which this rule applies.Click Create and open.
3. In the Method field, enter Call svcAddWorkObject. The svcAddWorkObject function creates a work object by using the flow rule specified in the Flow Type field.
4. In the Flow Type field, enter the flow rule based on the action you are performing. Here we use pyStartCase.
5. In the workPage field, enter pyWorkPage and Click Save.
Creating the service package:
1. In the Dev Studio header, click Create > Integration-Resources > Service Package.
2. In the Short description field, enter a meaningful description of the service package.
3. In the Service package name field, enter a name for the service package and click Create and open.
4. In the Service access group field, assign the appropriate access group.
5. Complete the rest of the rule form according to the business requirement and click Save.
Creating the service request processor for multi-threaded processing:
A service request processor is created on if we are using multi-threaded processing. A request processor enables asynchronous processing by defining a queue in Pega Platform that can have items placed in it for processing.
1. In the Dev Studio header, click Create > Integration-Resources > Service Request Processor.
2. In the Short description field, enter a meaningful description of the service request processor.
3. In the Service Package Name field, enter the name of the service package that you created.
4. In the Request Processor Name field, enter a name for this request processor and Click Create and open.
5. On the Queuing Options tab, in the Queue Class Name field, enter the System-Queue-ExecutionRequest-Service-Default class.
6. On the Dequeuing Options tab, configure when to remove items from the queue and click Save.
Creating the service file rule:
1. In the Dev Studio header, click Create > Integration-Services > Service File.
2. In the Label field, enter a description of the service.In the Customer Package Name field, enter the name of the service package that you created for this service.
3. In the Customer Class Name field, enter the appropriate name.Click Create and Open.
4. In the Primary page class field, specify the page class of the service activity or activities that you will specify on the Request tab.
5. Depending on how you configured the service activity, specify a page name.
6. On the Method tab, configure how the content of the files is organized.
If the files contain multiple records and records of different types need to be processed differently, select a processing method of either record at a time or by record type.
Use the Record layout and Record type identifier sections to specify how the service rule determines where one record ends and another record begins.
7. On the Request tab, in the Parse segments section, map the data from the file to the clipboard or a parse rule and specify the activity to use to process the data.
If the files contain multiple records and records of different types need to be processed differently, create as many rows as you need in the Parse Segments section.
If the records can be identified by type, use the Record Type field to indicate which processing definition to use for records of each type.
If different records always appear in the same sequence and there is no type indicator, use the order of the processing definitions to specify which activity or parse rule to use for each record type.
8. Click Save. Test the rule by clicking Actions > Run.
Creating the file listener:
To configure a file listener, complete the following steps.
1. In the navigation pane of Designer Studio, click Records > Integration-Resources > File Listener. Click Create.Complete the fields and click Create and open.
2. In the Properties page, in the Source properties section, enter details for the following required fields:
Source Location: file://<repository_name>/<optional_folder_path> where <repository name> specifies a repository. Here we have used D:\TestFile.
Source Name Mask: *.cvs, *,pdf, and so on. Enter the type to match the type of files that you want to listener to read and process.
3. In the Listener properties page, choose the appropriate parameters for the File Service for this File Listener: Service Package, Service Class, Service Method.
4. Configure the Process and Error Tabs.
5. With the parameters configured, click Test connectivity and verify the listener connectivity.
6. The File Listener Connectivity Test window opens and displays the status. After the Connectivity test successful status displays, click Save. The File listener is ready for use.
7. After finishing all the configurations click Designer Studio > System > Operations > System Management Application.
8. Initially there are no nodes available. So create a node.
9. In node creation select the local JVM Machine to read the file from local host. File Management can be done from that Node.
10. Create a local folder and and a normal text file and save it in .csv format.
11. After 30 seconds the file will be automatically read by the Pega Listener.
12. Here the finished work is work_Fileread. It can be opened and read from here.