Pega Platform provides the ability to define a package of rules, known as Service File rules, which are used to import data from character-based files into the system. This feature supports the processing of a variety of record-oriented file formats, enabling you to create or update objects within Pega as Pega Platform cannot directly process or parse binary files.
Some common file formats that can be imported include:
Text files
Comma-Separated Value (CSV) files
Completed PDF forms
A package of Service File rules works with a File Listener (from the Data-Admin-Connect-FileListener class) that references the package to handle file imports. To process the data in the files, the Service File rule can use one of these parsing methods:
Parse Structured – for structured data.
Parse Delimited – for data with separators (e.g., CSV).
Parse XML – for XML data.
To create a Service File rule in Pega Platform, follow these steps:
In the navigation pane of dev studio click on Records--> Integration-Services-->Service File-->Create.
On the new tab, enter following data,
In Label field, enter a descriptive name for the rule that clearly identifies your Service File rule.
In Customer Package Name field, enter the name of the service package that you created earlier. This service package is used to group related Service File rules together.
In the Customer Class Name field, enter the name of the class that logically groups the related methods for your file import service.
3. Click Create and open.
4. On the Service tab, in the Primary page class field, select the class for the primary page that is to be used in all activities run with this Service File rule. The system creates an empty page of this class each time it executes a row of the Parse Segments array on the Request tab.
5. Click the Method tab, and then in the Processing method field and select how the data is parsed and processed, based on the structure of the input file.
file at a time:
The system processes the entire file with the first parse segment. Any additional rows in the Parse Segment array are ignored after the first segment. This mode is suitable when the file contains only one record type or when you want to process the entire file in a single step.
record at a time:
The system processes the file sequentially, applying the parse segments to each record one by one. The first parse segment is applied to the first record, the second segment to the second record, and so on.
This is ideal when the file contains multiple records, and each record needs to be processed individually using the corresponding segment.
by record type:
Extract a record type from a fixed position in the record and use this value to determine which parse segment to apply to that record. Two other fields on this Method tab identify the byte offset position and length of the record type. The system matches the value extracted from the record with the Record Type field in the Parse Segment array.
6. In Record Terminator field, if the records in your input file end with a separator character, you can specify the delimiter that marks the end of each record. This setting is used when the Processing Method is configured to either record at a time or by record type.
You can enter a single character delimiter or use one of the following escape sequences for special characters:
\n – Represents a newline character.
\r – Represents a return character.
\f – Represents a form feed character.
\0 – Represents the null character.
\t – Represents a horizontal tab character.
7. Click on Request tab and configure the following.
Under Parse segments, Select "Once?" for this parsing segment.
This option is useful for files with one header record followed by multiple detail records, such as Microsoft Excel CSV files.
Select "Once" in the first row to apply the header parsing rule.
Leave this checkbox unchecked for subsequent rows to process the remaining detail records.
8. In the Map to field, enter the action to perform in a parse step. Select one of the following keywords or functions:
Clipboard
XML ParseRule
Delimited ParseRule
Structured ParseRule
Skip — Do not process this segment
9. In the Map to key field, enter the name of the Parse rule that you configured earlier, followed by the name of the root element of your manifest file. (ABC.csv)
10. In the Activity field, enter or select an activity to run after the data processed by this row is parsed and arrives on the clipboard.
11. Click Save.
Unit testing a Service File:
To test the service file, follow these steps:
Click on Actions → Run to execute the rule.
On the execution page, under Enter Request Data, you have two options:
Select Supply file content if you want to manually enter the file data.
Select the Upload a local file radio button if you have a test file ready.
3. In the File Content field, provide the contents of the test file, ensuring to include any delimiters. This text area is displayed when you select ‘Supply file content’ in the previous field.
4. In the File Location field, click "Choose File" to upload a test file. This field appears when you select ‘Upload a local file’ in the previous step.
5. Click on Execute to run.
--TEAM ENIGMA
Comentários