Use file services 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 your file directory and calls the file service so that you can easily import the contents of character-based files into your Pega Platform system.
The file listener monitors the file directory and calls the file service when files arrive. The file service might use a parse rule for XML, structured, or delimited data, or a JSON data transform to read the file and map the data into fields on the clipboard. A service activity processes the data, typically by creating a case from the file data and launching a flow.
Both the file listener and the file service have a role in processing the files:
- When files that match the listened for pattern arrive, the file listener calls the file service to process the file data.
- The file service processes the file by using the rules that you configured for it.
- Based on the file listener configuration, the file listener either deletes
the file or moves it to the
work_<name of listener>/completedsubdirectory.
- The listener also creates a
reportssubdirectory to hold report files that contain the processing results.
To configure the file service and file listener, perform the following steps:
- Create the file service rule to process your files. The most common use case is
to use a Parse Delimited rule to map properties to the fields in a CSV file. For
more information, see Creating a Parse Delimited rule.Additionally, you can use the following rules to configure a file service to process your files:
- Parse XML – Use a Parse XML rule to import XML files. For more information, see XML Stream rules.
- Parse Structured – Use a Parse Structured rule to process fixed-format flat files. For more information, see Creating a Parse Structured rule.
- JSON data transform – Use a JSON data transform to process data that is in JSON format. For more information, see Data transforms.
- Create 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. When you create the service activity, make sure that you enter the following values:
- In the Method field, enter Call
The svcAddWorkObject function creates a work object by using the flow rule specified in the Flow Type field. For example, you could call the BatchNewPolicy flow type to add the created work objects to a workbasket for processing new policies.
- In the workPage field, enter pyWorkPage.
For more information about creating a service activity, see Create or Save as form in AUT test suite.
- In the Method field, enter Call svcAddWorkObject.
- Create the service package that is required to group related Service File
rules. For more information, see Service Packages.
- Optional: If you are using multithread processing, create a service request processor. A
request processor enables asynchronous processing by defining a queue in
Pega Platform that can have items placed in it for
processing.For more information, see Viewing test coverage reports.
- To define how the system processes the files that the file listener pulls into your application, create a Service File rule. For more information, see Service File rules.
- Create the file listener that monitors your file directory and calls the file
service to process the data in the file.
- For Pega Cloud or on-premises users on systems running 7.2.2 or 7.3.1, see Configure a file listener associated with a storage destination in the archive on Pega Community.
- For Pega Cloud or on-premises users on systems running 7.4 and higher, see Configuring a file listener associated with a storage repository.
- Configuring a file listener associated with a storage repository
You can configure a file listener to monitor a specific folder in your repository and call a file service to process the files. With this configuration, you can better organize your files and create work items from a repository of related files. This task is specific to Pega Platform 7.4 and later.