Allow Unauthenticated or Guest Access to a Pega 7 Activity that Generates HTML Page

An Activity can be used in Pega 7 to process a HTML Rule using the Show-HTML method and to send the resulting page to a web browser.

Pega7.1.9 - Activity Processing HTML Rule using SHOW-HTML Method

For an example on how to create such an activity and HTML Rule, see the post:

  • The Activity is accessed through a URL such as the one shown below.
http://localhost:8080/prweb/PRServlet/?pyActivity=PGX-MyStore-Work.ViewHelloWorld
  • A login dialog appears and the user must provide valid Pega operator credentials to access the activity.

Pega7.1.9 - Access Activity Rule from Safari Web Browser via URL, Login Screen

  • After successful authentication, the Activiy is run and the HTML page is displayed in the browser:

Pega7.1.9 - Access Activity Rule from Safari Web Browser via URL, Hello World HTML Page

This post shows how a new RuleSet and Access Group can be used to provide access to the activity for unauthenticated or guest users. That is, there will be no login screen and the activity will be accessed as an unauthenticated guest user using the pega.BROWSER requestor type.

Summary

  1. Access Activity as Unauthenticated/Guest via URL with pzAuth Parameter
  2. Create a new Ruleset for Rules without Authentication
  3. Edit Access Group for Unauthenticated/Guest Users
  4. Save Rules into Ruleset for Unauthenticated Users
  5. Testing Access to the Activity Rule

Related Posts

  • To access the Activity as an unauthenticated guest user, the query string parameter pzAuth=guest is used, so that the URL is as shown below.
  • Ensure to send this request from a browser with no active Pega session (e.g. log out of Designer Studio).
http://localhost:8080/prweb/PRServlet/?pzAuth=guest&pyActivity=PGX-MyStore-Work.ViewHelloWorld
  • Without additional changes, the request will fail and Pega will return an error page, indicating that the request is Unauthenticated:

Pega7.1.9 - Activity Rule Access from Browser Error, Unauthenticated or not Available.

  • Requests from unauthenticated guest users will execute under the pega.BROWSER requestor type.
  • The Pega logs will indicate that the unauthenticated requestor does not have access to the specified activity rule.
Caused by: com.pega.pegarules.pub.generator.RuleNotFoundException: Failed to find a 
'RULE-OBJ-ACTIVITY' with the name 'VIEWHELLOWORLD' that applies to 'PGX-MyStore-Work'. 
There were 1 rules with this name in the rulebase, but none matched this request. 
The 1 rules named 'VIEWHELLOWORLD' defined in the rulebase are: 1 related to applies-to class 
'PGX-MyStore-Work', but were defined in rulesets which are not in your rulesetlist: 
'MyStore:01-01-01'.
  • The approach in this example is based on configuring a new RuleSet and using an access group for unauthenticated users to bypass Pega 7 login.

  • In Designer Studio, navigate to + > SysAdmin > RuleSet to create a new RuleSet.
  • Enter a name and version for the new rule set, here it is MyStoreUnauthenticated:01-01-01.

Pega7.1.9 - Designer Studio - Create new RuleSet Form

  • Click on Create and open.
  • Select Application Validation and set the Effective Start Date to today’s date or earlier.
  • Click on Save to continue.

Pega7.1.9 - Designer Studio - Edit RuleSet - Versions Tab

Add new Ruleset to Application Production Rulesets

  • Open your current application, here it is called MyStore.
  • On the Definition tab, expand the Advanced section and add the new RuleSet, here MyStoreUnauthenticated:01-01, to the list of Production RuleSets.

Pega7.1.9 - Designer Studio - Edit Application - Add Production Ruleset

  • Click on Save and continue.

  • Use the Records Explorer to view instances of Access Group.
  • Filter the list using your application name, here MyStore.

Pega7.1.9 - Designer Studio - Records Explorer - View Instances of Access Group

  • Pega 7 may have automatically created an access group ending in :Unauthenticated when creating the application.
  • If not, create a new access group using the +Create button.
  • Click on the row of that instance, here MyStore:Unauthenticated to edit the access group.

Pega7.1.9 - Designer Studio - Edit Access Group - Definition Tab

Pega7.1.9 - Designer Studio - Edit Access Group - Advanced Tab - Add Production RuleSet

Update the Requestor Type "pega.BROWSER"

  • Use the Records Explorer to view instances of SysAdmin > Requestor Type.

Pega7.1.9 Designer Studio - Records Explorer, View Requestor Types

  • Open the pega.BROWSER requestor type by clicking on the instance row.
  • This requestor type is configured to only have access as per access group PRPC:Unauthenticated.

Pega7.1.9 Designer Studio - Edit Requestor Type, Change Access Group

  • Edit the requestor type and set the access group to the one created earlier, here MyStore:Unauthenticated.

  • Open the current access group for authors of the application. Here it is MyStore:Authors
  • Add the RuleSet for unauthenticated access (see section 2…) to the list of production RuleSets.

Pega7.1.9 Designer Studio - Edit Access Group - Advanced Tab - Add Production Ruleset

  • Save the changes and logout of the Designer Studio and then login again.
  • Open the Activity rule, here named ViewHelloWorld and click on Save As.

Pega7.1.9 Designer Studio - Activity Save As - Unauthenticated RuleSet

  • Select Production Rulesets for Context, the appropriate Apply to class and the previously created RuleSet for unauthenticated users, here Unauthenticated:01-01-01.

Pega7.1.9 Designer Studio - Activity Save As - Production Ruleset Unauthenticated RuleSet

  • Click on Create and open to continue and then on Check in to commit the changes.
  • Repeat the steps for the HTML Rule used in the Show-HTML step, here HelloWorldHTML.
  • Modify the HTML Rule as needed to customize it for unauthenticated guest users.

Pega7.1.9 Designer Studio - Edit HTML Rule - HelloWorldHTML

  • Save and Check in the changes.
  • Remove the ruleset for unauthenticated users from the list of production rulesets for the access group that is used to login when accessing the activity (…or create a new access group).

Pega7.1.9 Designer Studio - Edit HTML Rule - HelloWorldHTML

  • In a new browser session, access the activity as an unauthenticated user with pzAuth=guest:
http://localhost:8080/prweb/PRServlet/?pzAuth=guest&pyActivity=PGX-MyStore-Work.ViewHelloWorld

Pega7.1.9 Designer Studio - Access Activity as Unauthenticated Gues User from Browser

  • In a new browser session, access the activity as an authenticated guest user without the pzAuth parameter:
http://localhost:8080/prweb/PRServlet/?pyActivity=PGX-MyStore-Work.ViewHelloWorld
  • A login screen will appear. Enter the credentials of a Pega 7 operator ID that does not have access to the ruleset for unauthenticated users.

Pega7.1.9 Designer Studio - Access Activity as Authenticated User from Browser - Login Screen

  • The HTML Rule rule for authenticated users is applied and the page is rendered as shown below.

Pega7.1.9 Designer Studio - Access Activity as Authenticated from Browser

Using a Pega 7 Activity to Show HTML Page and Access the Activity from Web Browser

An Activity can be used in Pega 7 to process a HTML Rule and send the resulting content to a web browser. This is known in Pega as stream processing. The Activity is accessed with a HTTP request using a URL.

Summary

  1. Create new HTML Rule
  2. Create an Activity to Process HTML Rule using Show-HTML Method
  3. Access the Activity from a Web Browser

Related Posts

  • In the Pega 7 Designer Studio, click on +Create > Technical > HTML to create a new HTML Rule.

Pega7.1.9 Designer Studio Menu - Create HTML Rule

  • Enter a label for the new HTML Rule, select the context, apply to class and ruleset version.
  • Here, the name of the new rule is HelloWorldHTML. Then click on Create and open.

Pega7.1.9 Designer Studio - Create New HTML Rule

  • On the HTML tab of the HTML Rule, select "HTML" in the Generate for drop down.
  • Here, Browser Support is set to "All Supported Browsers" and Accessibility remains "No".
<html>
  <body>
    <span>Hello World!</span>
  </body>
</html>
  • Enter HTML code into the source text box, e.g. the above code shows a Hello World! message.

Pega7.1.9 Designer Studio - Edit HTML Rule, add Hello World in HTML source text box

  • Click on Save to save the changes to the HTML Rule.

  • In the Pega 7 Designer Studio, click on +Create > Technical > Activity to create a new Activity Rule.

Pega7.1.9 Designer Studio Menu - Create Activity Rule

  • Enter a label for the new Activity Rule, select the context, apply to class and ruleset version.
  • Here, the name of the new rule is ViewHelloWorld. Then click on Create and open.

Pega7.1.9 Designer Studio - Create New Activity Rule

  • On the Pages & Classes tab of the Activity rule, add a reference to the class that contains the HTML Rule. Here, that class is PGX-MyStore-Work.

Pega7.1.9 Designer Studio - Edit Activity Rule, Pages and Classes Tab

  • On the Steps tab of the Activity rule, add two steps as shown below.
  • The first step uses Page-New to create a new clipboard page of the class that contains the HTML Rule.
  • The second step uses Show-HTML and references HelloWorldHTML in the HTMLStream parameter.

Pega7.1.9 Designer Studio - Edit Activity Rule, Steps Tab

  • Check the option "Allow direct invocation from the client or a service" on the Security tab of the Activity rule.
  • The option "Require authentication to run" is left unchecked.
  • Leave the Usage dropdown unchanged so that it is set to "Activity".

Pega7.1.9 Designer Studio - Edit Activity Rule, Security Tab

  • Click on Save to save the changes.
  • The activity can now be run by clicking on Actions > Run.
  • On the pop-up Run Activity window, click on Run to execute the activity.

Pega7.1.9 Designer Studio - Run Activity Rule

  • The HTML page, generated by the activity, is shown in a new window:

Pega7.1.9 Designer Studio - Run Activity Rule, Output

  • In Google Chrome, right-click on the page and select View Page Source.

Pega7.1.9 Designer Studio - Run Activity Rule, Output, View Page Source

  • Here, the HTML code is not modified and retains all white spaces and line breaks.
  • The option "Omit extra spaces?" on the HTML Rule form can be used to remove white spaces and line breaks to reduce the size of the generated HTML code.

Pega7.1.9 Designer Studio - Edit HTML Rule, Omit Extra White Spaces

  • The HTML code is now reduced to one line and consecutive white spaces are replaced with a single white space.

Pega7.1.9 - Run Activity Rule, Omit Extra White Spaces

  • The activity can be accessed from an external browser or other HTTP client via a URL.
  • The target activity is referenced in the pyActivity query string parameter using the class- and activity name, here PGX-MyStore-Work.ViewHelloWorld, so that the URL in this example is:
http://localhost:8080/prweb/PRServlet/?pyActivity=PGX-MyStore-Work.ViewHelloWorld
  • If the activity is accessed from the same browser that is used to work in the Designer Studio, the current user’s session will be used to invoke the activity:

Pega7.1.9 - Access Activity Rule from Chrome Web Browser via URL

  • If the activity is accessed from a different browser, where no active session is present, a login screen will be shown:

Pega7.1.9 - Access Activity Rule from Safari Web Browser via URL, Login Screen

  • Use valid Pega operator credentials for authentication when calling the activity (…even when the option "Require authentication to run" is NOT checked, authentication to Pega is needed).

Pega7.1.9 - Access Activity Rule from Safari Web Browser via URL, Active Session

Allow Direct Invocation from the Client or a Service

  • If the option "Allow direct invocation from the client or a service" is NOT checked on the Security tab of the activity:

Pega7.1.9 Designer Studio - Activity Security, Allow direct invocation from the client or a service

  • It is not accessible by an external client and Pega will send an error page:

Pega7.1.9 - Access Activity Rule from Safari Web Browser via URL, Error Page

  • The Pega logs will show a more descriptive error message:
2017-10-31 14:06:35,741 [http-nio-8080-exec-2] [  STANDARD] [          ] [    MyStore:01.01.01]
(internal.mgmt.Executable) ERROR localhost|0:0:0:0:0:0:0:1 [email protected] - 
This activity may not be called directly from input: 
RULE-OBJ-ACTIVITY PGX-MYSTORE-WORK VIEWHELLOWORLD #20171030T210946.682 GMT

Require Authentication to Run Activity

  • If the option "Require authentication to run" is NOT checked, Guest users can run the activity (…if they meet other security and access criteria) using the URL parameter pzAuth:
http://localhost:8080/prweb/PRServlet/?pzAuth=guest&pyActivity=PGX-MyStore-Work.ViewHelloWorld
  • By default, guest users –unauthenticated requestors– can only access rules in the rulesets provided by the access group PRPC:Unauthenticated.
  • This activity is not included in that ruleset and therefore an error page is shown for guest users and an error appears in the Pega 7 logs::
2017-10-31 14:07:04,171 [http-nio-8080-exec-4] [  STANDARD] [          ] [    MyStore:01.01.01] 
(internal.mgmt.Executable) ERROR localhost|0:0:0:0:0:0:0:1 [email protected] - 
This activity may not be called directly from input:
RULE-OBJ-ACTIVITY PGX-MYSTORE-WORK VIEWHELLOWORLD #20171030T210946.682 GMT 
com.pega.pegarules.pub.PRRuntimeException: 
Error: You lack access required to execute PGX-MyStore-Work.ViewHelloWorld
  • For details on how to make the activity accessible to guest users and how to setup different HTML rules for authenticated users and guest users, see the post:

How to Use Expressions and Pega 7 Library Functions for String Manipulations in a Data Transform or Activity

For this post, Pega 7.1.9 was used. Pega 7 (and earlier versions) provides several utility functions for manipulating Strings.
These functions can be called as part of Expressions in Data Transforms and Activities.

Summary

  1. Sample Data Transform and Debugging
  2. Examples of String Manipulations with Expressions and Functions
    1. Conversion to Upper- and Lower Case
    2. Extraction of Substrings
    3. String Comparison
    4. Substring Search
    5. Substring Replace
    6. String to Number Conversions

Related Posts

  • For this example, a data transform with 7 input parameters was created:

Data Transform - TransformNames - Parameters Tab

  • On the Definition tab, the Set action is used to assign new values to the parameters using expressions. Here, Param.fullName is set using concatenation and conversion to upper case.

Data Transform - TransformNames - Set Action and Expression Builder Gear Icon

Data Transform - TransformNames - Pega 7.1.9 Expression Builder

  • The data transform can be run by clicking on Actions > Run.
  • Use the Trace button to start the Tracer. This allows to view the transformed input parameter values.

Data Transform - TransformNames - Run Data Transform Page

  • The data transform’s execution page can be viewed by clicking on the FIRST row in the Tracer (…execution page state after running the data transform).

Data Transform - TransformNames - Run Data Transform - Steps Execution and debugging in Tracer

  • Click on the =unnamed= link in the Parameter Page Name row to open the parameter page.

Data Transform - TransformNames - Tracer Debugging - View Trace Event

  • Here, the parameter page shows the data transform’s parameters AFTER execution is completed.

Data Transform - TransformNames - Tracer Debugging - View Data Transform Parameter Page

  • The Pega 7 String Library functions use the methods of the java.lang.String class. But, NOT ALL methods of java.lang.String are included in the Pega 7 String library.

A: Conversion to Upper- and Lower Case

  • Changing the case of a String is straightforward. Here, a single input String is converted to upper case.
    @String.toUpperCase(Param.firstName)
    "ULYSSES"
  • Likewise, a method exists for changing the case of a single input String to lower case.
    @String.toLowerCase("Ulysses S. Grant")
    "ulysses s. grant"
  • The + operator can be used for concatenating multiple parameters to one input parameter:
    @String.toLowerCase(Param.firstName + " " + Param.middleName + ". " + Param.lastName)
    "ulysses s. grant"

B: Extraction of Substrings

  • There are two overloaded @String.substring methods (same name, different input parameters) that can be used to extract a substring from a given string. The first one has 3 input parameters, the string (zero indexed) and a start-(inclusive) and end index (exclusive) and uses to the Java method substring(int beginIndex, int endIndex).
    @String.substring("304-678-9185 EXT 776", 0, 12)
    "304-678-9185"
  • To extract the last 4 digits of the phone number:
    @String.substring("304-678-9185 EXT 776", 8, 12)
    "9185"
  • The second substring method only has 2 input parameters, the string and the start index.
  • To extract the extension in this example, use:
    @String.substring("304-678-9185 EXT 776", 17)
    "776"
  • The result of a function can be passed as an input parameter to another function. Here, the 10-digit phone number is extracted first. Then, the area code is extracted:
    @String.substring(@String.substring("304-678-9185 EXT 776", 0, 12), 0, 3)
    "304"
  • @String.length is used to obtain the length of a given string, i.e. the number of characters:
    @String.length("Blueberry")
    9

C: Comparison

  • @String.equalsIgnoreCase is used to compare two Strings (case-insensitive). For example:
    @String.equalsIgnoreCase(Param.firstName, Param.lastName)
    false
  • @String.notEqualsIgnoreCase is used to compare two Strings for INEQUALITY. For example:
    @String.notEqualsIgnoreCase(Param.firstName, Param.lastName)
    true
  • @String.equals is used for CASE-SENSITIVE comparison:
    @String.equals("Blue", "blue")
    false
  • @String.notEquals is used for CASE-SENSITIVE comparison for INEQUALITY:
    @String.notEquals("Blue", "blue")
    true

D: Substring Search

  • @String.contains is used to search for the occurrence of a given substring within a string:
  • Here, Param.street is "Oak Hill Dr" and the method is used to check if it contains "Hill".
    @String.contains(Param.street, "Hill")
    true
  • @String.pxContainsViaRegex is used to search for the occurrence of a given substring within a string using a regular expression. For details on regular expressions, see the java.util.regex.Pattern class documentation.
  • In this example, a regular expression, \d{3}-\d{3}-\d{4}, is used to search for 10-digit phone numbers in a given String. Note that the \ character needs to be escaped as per Java syntax, using \\.
    @String.pxContainsViaRegex("phone=345-444-0001|name=smith", "\\d{3}-\\d{3}-\\d{4}", true)
    true
  • @String.startsWith is used to check if a string starts with a given substring.
  • @String.endsWith is used to check if a string ends with a given substring:
    @String.endsWith(Param.street, "Dr")
    true
  • @String.indexOf can be used to get the start index of a substring within a given String.
    @String.indexOf(Param.street, "Hill")
    4
  • If the given substring is NOT found, @String.indexOf returns -1, for example:
    @String.indexOf("Oak Hill Dr", "Blvd")
    -1
  • @String.indexOf is often used with @String.substring.
  • For example, Param.inputRow is "Name=Warren". To extract the actual name:
    @String.substring(Param.inputRow, @String.indexOf(Param.inputRow, "=") + 1)
    "Warren"

E: Substring Replace

  • @String.replaceAll is used to replace all occurrences of a given string with another string.
  • In this example, all of the hyphen characters are replaced with pipe characters:
    @String.replaceAll("apple-banana-cherry-date", "-", "|")
    "apple|banana|cherry|date"
  • @String.pxReplaceAllViaRegex is used to replace all substrings that match the given regular expression. For details on regular expressions, see the java.util.regex.Pattern class documentation.
  • For example, to replace all 10-digit phone numbers in a String with XXX-XXX-XXXX:
    @String.pxReplaceAllViaRegex(
    "Mr.Smith's work phone number is 675-999-0017 and his cell phone is 778-000-9999.",
    "\\d{3}-\\d{3}-\\d{4}",
    "XXX-XXX-XXXX")
    "Mr.Smith's work phone number is XXX-XXX-XXXX and his cell phone is XXX-XXX-XXXX."

F: String to Number Conversions

  • @String.isInteger is used to validate that a given String represents a number of type Integer:
    @String.isInteger("178")
    true
  • @String.isDouble is used to validate that a given String represents a number of type Double:
    @String.isDouble("199.49")
    true
  • Strings that represent Integer and Double type numbers can be converted to Integer and BigDecimal Java types:
    @String.toInt("149")
    149
  • If the String does not contain a valid Integer value, the function returns 0.
    @String.toInt("99.99")
    0
  • @String.toDecimal supports thousands separators and a decimal point:
    @String.toDecimal("1,250,599.39")
    1250599.39

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

Summary

  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!