Notifications in Pega – Part 4 – Read published message
In this blog article, we will see how Pega Subscribers can read the published event messages
This is the continuation of the previous article, where we published a custom notification message as soon as the case is assigned to the Sales Work basket.
Please go through the article series in order number for better understanding.
https://myknowtech.com/tag/notification
I am going to reuse all the configurations which I used in the previous article and do only a little customization for this article.
Actions already completed are
1. A notification channel – Refresh Work queue was created
Update – Add additional property – pyMessageLabel
2. A notify activity was created – RefreshAssignmentNotification
– Add an additional parameter – Message in the Parameters tab.
– Do the additional property-set in step 2 for pyMessageLabel
3. Update the notification flow configuration to pass the Message
Save all those rules.
First, let’s catch the published message from the developer tools.
Step 1: Open the developer tools – networks tab – WS selected.
Step 2: Create a new case to send the notification.
Step 3: Click on the new message to view the JSON message structure.
Note down the message JSON structure.
Now the interesting part to read the message.
Important note: With the latest Pega versions, you can read the message only by using Javascript function!
Let’s start the implementation.
How to read published notification messages?
Step 1: Create a new JavaScript file – HandleWebSocketFunctions
Note: You can reuse the script in any existing text file or in any non-auto generated section.
Step 2: Include a new function – handleRefreshAssignmentCallback in the text file rule.
The input for the function is data = which can be mapped to event data from the UI.
I am reading two property values – pyAssignmentOwner and pyMessageLabel and putting it into console log to unit test.
You can see how the message data gets passed to the function as parameter and parsed into individual variables.
Save the text file rule.
Step 3: Include the JavaScript file in the corresponding harness rule.
Now on loading the harness (dashboard), the JavaScript function will be registered within the browser.
Step 4: Use the callback function in the section action-set.
Update the action-set for function callback. Pass the data parameter value as event data.
Save the section.
We are done with the configurations. Let us test the changes.
Step 1: Open the developer tools – console tab.
Step 2: Create a new case and check the console logs.
You see our Pega function executed successfully, read the published message and logged the same in console
Good sign.
You are able to capture the event messages in JavaScript variables.
Next action? – You know you can do all types of processing inside a JavaScript function like creating a new case, call activity, data transform etc.
You can check the link for more details – https://collaborate.pega.com/question/how-call-data-tranform-using-javascript
Play whatever you want with the event data.
As a summary,
– Create a new notification channel and publish the message to client browsers
– Create a new JavaScript function to read the published message.
We are at the end of the notification series posts.