Skip to main content
The activity attaches an exported file to a Pega case. It loads the JSON request, retrieves the case by its ID, and links the file to the case.

Create the activity

1

Name the activity

In the POST request of the service, type a name for your new activity in the Activity name field, for example UploadFileToCase.
2

Open the activity

Click Create and open to configure the new activity.
3

Declare the accessed classes

On the Security tab, add the classes that the method and the activity access: Pega-API-CaseManagement and Work-.
4

Declare the pages and classes

On the Pages & Classes tab, declare the classes used by the activity:
  • AttachmentPage of type Data-WorkAttach-File
  • pyWorkPage of type Work-
In Pega, a page corresponds to a class object.
5

Add the parameters and local variables

On the Parameters tab, add the following parameter:
  • FileStream of type String – Contains the contents of the file in Base64.
Add the following local variable:
  • IsConverted of type Boolean – Contains the result of executing the method that converts the JSON object in the POST request into global variables of myStepPage.

Activity steps

On the Steps tab, create new steps for the methods that load the objects and link the case to its file.

Load the JSON object from the POST request

Set Method to Property-Set and Step page to .createCaseRequest. Convert the result of the @(Pega-RULES:Page).pxConvertStringToPage(tools, myStepPage, Param.Request,"json") method to the Local.IsConverted variable. The value is true when the JSON object from the POST request is successfully converted to the myStepPage object, and false otherwise. After the myStepPage object has been populated, populate the activity variables with Param.FileStream = .FileStream. To add new properties to myStepPage, click the target icon on the right, and then click Create and open on the Create Property form.

Get the object containing the case by its ID

Set Method to pxGetCase: Call pxGetCase to call the activity. In the Step page field, type the name of the object that will store the pyWorkPage result. In the WorkObjectId parameter, type Param.CaseId, which is the case ID.

Create the empty AttachmentPage object

AttachmentPage is the object declared on the Pages & Classes tab. Set Method to Page-New and Step page to AttachmentPage, and leave the method parameters empty.

Populate the AttachmentPage parameters

Set Method to Property-Set and Step page to AttachmentPage. Populate the parameters with the following values: Use the Obj-Save method to save the AttachmentPage object. Use the Link-Objects method to link the pyWorkPage object, which is the case obtained with pxGetCase: Call pxGetCase, to the AttachmentPage object. Set the parameters as follows: Use the Commit method to commit the changes to the database.

Return the response

If necessary, write the pyWorkPage object received in the response from the service to Param.Response, converting it with @(Pega-RULES:Page).pxConvertPageToString(tools, pyWorkPage, "json").