How to Delete Case Type Instances in Pega 7 with an Activity

This example shows how the Designer Studio can be used to view case type instances and how an Activity can be used to delete case type instances from the PRPC database in Pega 7. The activities in this tutorial will use the Obj-Delete-By-Handle and Obj-Browse methods to either delete single instances or multiple instances. Note that case type instances should not be deleted this way in a production environment. Please refer to the Purge and Archive Wizards for information on how to delete and archive old work on production systems.

Related Posts


  1. View Instances of Case Type Rule in the Pega 7 Designer Studio or DB Tool such as pgAdmin
  2. Delete a Single Case Type Instance by Handle with Obj-Delete-By-Handle
  3. Delete Multiple Case Type Instances with Obj-Browse and Obj-Delete-By-Handle

For this example, a case type called Auto has been created to capture the processes needed for providing auto insurance quotes to customers. The Auto case consists of 3 stages as shown in the screen shot below. Customer and vehicle information is collected and used to calculate an auto insurance quote. When running the case type rule, new instances are created and stored in the PRPC database.

Case Designer Auto Case Type Stages

The Designer Studio can be used to view all instances of a given case type rule. Navigate to the Application Explorer and right click on the case type rule. In the context menu, hover over View and click on Instances as shown in the screen shot below.

Case Designer open Application Explorer and View Case Type Instances

A list type report will execute and show all instances of the case type rule. In this example, there are 44 instances of the ABC-Insurance-Work-Auto case type rule. The list report shows the unique instance names, when the instances where last updated and by what operator. In the below example, the instance names are A-2, A-3, A-4 and so on. An instance name is automatically generated by PRPC when a new case type instance is created.

Case Designer View Instances of Case Type Rule

It is also possible to use an external database client to view the case type instances. In this case, PRPC is using PostgreSQL for the database. For detailed instructions on how to use the pgAdmin client for connecting to and viewing the PRPC database, please refer to this blog post. The pgAdmin client can be used to look at the Auto case type instances stored in a database table in the PegaDATA schema.

In order to identify the table name, open the Auto class in the Designer Studio by navigating to the Application Explorer and expanding the case type rule. Next, expand the SysAdmin item and then expand the Class item and click on the actual class name of the case type rule to open the Edit Class form. Here, the class name is ABC-Insurance-Work-Auto and the class group name is ABC-Insurance-Work.

Designer Studio Edit Class Test Connection ABC-Insurance-Work-Auto

On the Edit Class form, scroll down and click on the button Test Connection. A new dialog will pop up and show the actual table name in the PegaDATA schema. In this case, since the class belongs to a class group, the instances are stored in a table for the class group class. In this example, the table name is: pc_ABC_Insurance_Work.

Class Test Connection ABC-Insurance-Work-Auto

The external DB tool, such as pgAdmin in this example, can be used to navigate the PegaDATA schema schema and open the pc_ABC_Insurance_Work table to view the case type instances.

pgAdmin navigate PRPC database schemas

In pgAdmin, right clicking on a table name allows to view the rows in that table. The below screen shot shows the instances of ABC-Insurance-Work-Auto:

pgAdmin view ABC-Insurance-Work-Auto instances in PegaDATA

An activity can be used to delete a single case type instance by its handle. To create a new activity for this purpose, right click on the case type rule in the Application Explorer and hover over +Create and then Technical and click on Activity.

Application Explorer Create new Activity

The Create Activity form will be loaded. Enter a meaningful label and leave the Apply to class so that it matches the case type rule for which instances should be deleted. Select a ruleset and click on the Create and open button.

Designer Studio Create New Activity Form

Parameters tab: On the Edit Activity form, navigate to the Parameters tab and add a mandatory input parameter instanceHandle (i.e. ID) that will hold an instance handle and then click on Save.

Application Explorer Edit Activity Parameters Tab

Steps tab: On the Steps tab, add a step that calls the method Obj-Delete-By-Handle. Expand the method and set the InstanceHandle method parameter by referring to the input parameter created earlier. Also check the checkboxes Lock, ReleaseOnCommit and Immediate to obtain a lock for the instance that is to be deleted and to commit the database operation immediately.

Edit Activity Steps Tab Obj-Delete-By-Handle

Security tab: On the Security tab, check the option Allow direct invocation from the client or a service so that the activity can be run directly in the Designer Studio.

Edit Activity Security Tab

Save the activity and unit test it by clicking on Actions > Run. Enter the instance handle on the test page. The instance handle is a string composed of the class group name and the instance name. Note that the Auto class belongs to class group ABC-Insurance-Work.

For example, the instance handle for the Auto case type instance with the name A-2 is ABC-Insurance-Work A2. Click on Execute to run the activity.

Run Activity Test Page

A confirmation message will indicate that the activity executed successfully. Use the methods described earlier to view the instances of the Auto case type rules and confirm that the instance has been deleted from the database.

Run Activity Confirmation Page

Instead of deleting a single case type instance by handle, multiple instances can be deleted as well. In this example, all instances that have not been updated since a given data time are deleted. The below screenshot shows the instances again, ordered in descending order by UPDATED ON property. There are a total of 43 instances.

The activity should delete all instances that have not been updated since 9:00 AM May 5th, 2016. In the below example, 27 instances would be deleted because the UPDATED ON property of the top 16 instances is greater than 9:00 AM May 5th, 2016.

Designer Studio View Instances of Case Type ABC-Insurance-Work-Auto

Create a new Activityin the same way as before:

Application Explorer View Case Type Instances

Give the new activity an appropriate label:

Designer Studio Create new Activity form

Click on Create and open and navigate to the Pages and Classes tab and add a page of type Code-Pega-List. Here, the page name is AutoCaseList

Edit Activity Pages And Classes Tab

Security tab: As before, check the option Allow direct invocation from the client or a service so that the activity can be unit tested. Save the changes and navigate to the Steps tab.

Edit Activity Security Tab

Steps tab: On the Steps tab, add a step that calls the Obj-Browse method and in the PageName field, enter the name of the Code-Pega-List page defined on Pages and Classes, in this case it is AutoCaseList. Also set the name of the class in the ObjClass field, here it is ABC-Insurance-Work-Auto.

  • The Obj-Browse method allows to set filter criteria. Here, we want to retrieve all instances where the UPDATED ON date is less than 9:00 AM May 5th, 2016.
  • The corresponding property is called pxUpdateDateTime. The condition is set to Is Less Than and the value is a DateTime string of the format YYYYMMDDTHHMMSS.QQQ.
  • According to that pattern the string for 9:00 AM May 5th, 2016 is "20160505T090000.000".
  • Save the activity and trace its execution by clicking on Actions > Trace and then run it by clicking on Actions > Run.

Edit Activity Run Activity

  • In this example, the Tracer will show 27 instances that match the Obj-Browse query with the filter on the last updated date.

Run Activity and view in Tracer

  • In order to delete these instances, add a loop step in the activity as shown below.
  • When clicking on the Loop button in a step, a dialog pops up.
  • Select For Each Embedded Page in the Repeat drop down and specify the class of the items in the page list, in this case it is ABC-Insurance-Work-Auto.

Edit Activity Add Loop Step For Each Embedded Page

  • Set the method to Obj-Delete-By-Handle and the step page to the page that holds the results of the Obj-Browse method and refer to pxResults, which is a list of the actual case type instances.
  • In this case, the step page for the iteration is AutoCaseList.pxResults. Check the method parameters Lock, ReleaseOnCommit and Immediate.
  • Most importantly, set the InstanceHandle dynamically using the pzInsKey value of each instance item.

Edit Activity Add Loop Step Obj-Delete-By-Handle

  • Save the changes and run the activity by clicking on Actions > Run and then on Execute on the activity test page.

Run Activity Execute Activity Test Page

  • A confirmation message will indicate that the activity was executed successfully, but returned no data.

Run Activity execution confirmation page success

  • Use the Designer Studio to view the instances again. In this case, 27 out of the original 43 instances have been deleted and only 16 instances remain in the PRPC database.

Application Explorer View Case Type Instances after delete 16 remaining

Please register and leave comments or suggestions on how to improve this example!

One thought on “How to Delete Case Type Instances in Pega 7 with an Activity

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.