Create a new activity within the application that you would like to delete case instances from. You can do this by going to App, right-click the app that you would like the case instances to be deleted from. My app is Nearest Store-> Create -> Technical -> Activity
2. Give you activity a title and Open it to begin adding fields
3. First, under the Security tab, check to “Allow direct invocation from the client or service”
4. Next on the Pages & Classes tab, create a page name that is unique to your app, so my app is NearestStore so my page name would be “NearestStoreCaseList”
5. The first method to add is “Obj-Browse”. Under the Method Parameters, set the PageName to your page name from Step 4. Set the ObjClass to the class that you would like your instances to come from, you can double check what this is by selecting your app from the app menu and copying the full name, ex. “OCQHGW-Claims-Work-YourApp”. Set the MaxRecords to your MaxRecords limit. Check “GetRowKey”, set RowKey to “pzInsKey” next in the Label check the “Select Field” and enter your criteria that you will select your instances based on. In my case, I am selecting my instances based on their UpdateDateTime. The format is “YYYYMMDDTHHMMSS.QQQ”. I’m searching for dates before August 29th, 2018 at 2:32 pm, ex. "20180829T143200.000"
6. Save your instances and Trace and Run your activity.
7. Since I had three instances that met the criteria, that should be reflected in my tracer results
8. If you do not see the set amount that matches the number or results that were supposed to be returned you may need to add more items to. Be visible in your tracer. To do this, click Settings and select “DB Cache”, “DB Query”, and “Data Pages”
9. If you would like to make sure that your query is correct with the time etc. Click on the number of results returned in your tracer and the details should pop up. As you can notice, the timestamp here shows 15:32 instead of 14:32, Pega seems to have issues with the times after 12 pm, but I believe this is still considered “2:32 pm”
10. Now that your results are being returned, let’s add one more step to our activity. In our activity, we’re going to add “Obj-Delete-By-Handle” as the method and the page is your PageName.pxResults. In the Method Parameters, set the InstanceHsndle to “.pxInsHandle”, check the Lock, ReleaseOnCommit, and Immediate checkboxes and save your activity.
11. Click on the Loop Button. In the Repeat Dropdown select “for each embedded page”, In the Only loop for certain Classes, select the class that contains the instances that you are deleting from. Click the Submit button.
12. Now run your activity. Here you can see the steps taken to delete the instances.
13. Finally we will check that our instances were deleted. We had three instances that met our criteria originally, N-1, N-2, and N-3 so they should not appear in our instance list:
14. As you can see the lowest instance is N-4 which means that N-1 – N-3 were removed from our DB
***Edited by Moderator Marissa to update Product***
There is also an activity defined @baseclass called pxDeleteClassInstances that is really useful during development and testing.
It can be used to delete case instances along with assignments, attachments, pulse posts, and other records related to a case instances being deleted but it doesn't take in any filtering parameters like you've outlined how to achieve.
In App Studio (formerly known as Express) we expose this as a menu option to "Delete cases" in the case explorer for users with the privilege: pxDeleteCasesAndCaseTypesInExpress