Discussion
![](https://accounts.pega.com/sites/default/files/styles/user_image/public/1689945000/de627806-229b-451b-ba18-fcfb054a6536.jpg?itok=gQXDYohQ)
Pegasystems Inc.
JP
Last activity: 20 Aug 2024 12:33 EDT
How to replace Connect File implementation with Repository API approach
Hi,
To write an output file to filesystem, we used to develop Connect File. However, starting with Pega 8.7, Connect File is deprecated and instead, Repository API should be used going forward. Existing Connect File rule will continue to function, but you cannot create new rules any longer (you can use and modify existing rules). For your reference, I will share how our customer implemented their requirements using Connect File, and how we replaced it with Repository API.
1. PoC Requirements
End user displays a list of work objects in a table structure. When a button is clicked, system generates an output file of work list in CSV format and writes it to application server's filesystem. Usually the output file is put to a remote File Server but in this PoC, I will save it to the local C drive as below.
2. Connect File implementation (old approach)
2-1. Create UI that displays a list of work objects as below. Place a button to trigger an activity.
2-2. Configure an activity. Construct CSV strings and execute Connect-File passing the file contents as parameter.
Pages & Classes
2-3. Create Connect File rule.
2-4. Now you can test. Click a button and make sure the CSV file is written to the directory successfully.
3. Replace with Repository API (new approach)
3-1. Create a Repository rule. You may have to add PegaRULES:RepositoryAdministrator access role to your access group if you don't have access to Data-Repository class. After creation, click "Test connectivity" button and make sure connection status is SUCCESS.
3-2. Modify the activity that we created earlier. Step 1 and Step 2 are the same. I've added Step 3, 4, and 5 for Repository API execution. Be noted, the CSV strings have to be encoded by Base64 before passing to D_pxNewFile data page. Then save the savable data page to write a file.
Pages & Classes
3-3. Now you can test. The output file must look exactly the same as previous Connect File approach.
- Notes
In this particular example, I have used String approach (pyContents) for D_pxNewFile data page. You can also use Stream approach (pyStream) if required. For large files, consider Stream approach. The maximum file size limit is 5GB. Please refer to https://support.pega.com/discussion/how-use-repository-api for how to use Repository API.
Hope this helps.
Thanks,