An Activity in Pega 7 can be used to process a HTML Rule and send the resulting content to a web browser. This is known in Pega as stream processing. This post shows how to create a Pega 7 activity to show HTML page that is accessible from a web browser with a URL.
- Create new HTML Rule
- Create Pega 7 Activity to Show HTML Page Using Show-HTML Method
- Access Pega 7 Activity to Show HTML Page from a Web Browser
1 Create new HTML Rule
- In the Pega 7 Designer Studio, click on +Create > Technical > HTML to create a new 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.
- 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.
- Click on Save to save the changes to the HTML Rule.
2 Create a Pega 7 Activity to Show HTML Page Using Show-HTML Method
- In the Pega 7 Designer Studio, click on +Create > Technical > Activity to create a new 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.
- On the Pages & Classes tab of the Activity rule, add a reference to the class that contains the HTML Rule. Here, that class is
- 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
HelloWorldHTMLin the HTMLStream parameter.
- 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".
- 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.
- The HTML page, generated by the activity, is shown in a new window:
- In Google Chrome, right-click on the page and select 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.
- The HTML code is now reduced to one line and consecutive white spaces are replaced with a single white space.
3 Access Pega 7 Activity to Show HTML Page from a Web Browser
- The activity can be accessed from an external browser or other HTTP client via a URL.
- The target activity is referenced in the
pyActivityquery string parameter using the class- and activity name, here
PGX-MyStore-Work.ViewHelloWorld, so that the URL in this example is:
- 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:
- If the activity is accessed from a different browser, where no active session is present, a login screen will be shown:
- 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).
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:
- It is not accessible by an external client and Pega will send an 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 firstname.lastname@example.org - 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
- 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@example.com - 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: