Subscribing to an Event

This topic provides an overview of how you can create subscriptions to an event.

Use IWC to subscribe an event occurring on a PeopleSoft page, where the event model is mapped to page elements, such as fields and grids. Creating a subscription does not require any changes to the page. When the event is published from the server, the page is updated automatically with the event data.

See event data structure in, Defining Events.

To subscribe to an even through IWC:

  1. Identify the component which needs to subscribe to the event.

  2. Navigate to the content reference for the component using the portal Structure and Content interface (PeopleTools > Portal > Structure and Content).

  3. Click theIWC Message Events link on the Content Ref Administration page of the component.

  4. Select Add a New Value, and add a new row on the IWC Message Events page, specifying these values:

    • Event Name: Enter a name to identify the event.

    • Message Event Type: Select Server Sub.

  5. Click the Map to display the Map Events Data to Page Elements page.

Image: Map Events Data To Page Elements Page

In this page you can map the data model of a published Event to a page element defined as <Record Name>_<FieldName>.

Map Events Data to Page Elements page

Field or Control

Definition

Event Name

Displays the Event Name that is defined in Content Reference Message Events page.

Page Name

Select the page where you want the event subscription added.

Page widget Type

Select from field or grid widget type inside the page which is auto-updated with the published event data.

Event Data

Select the meta-data of the event. The drop down will display key values if the event data type is KeyValue Pair and record fields if the event data type is PeopleCode Rowset.

Page Record Field Name

Select the record field name for the page element, which will update.

When using programmatic subscription, you are able to render the published event data on the page in any form using the JavaScript Object Notation (JSON) data-interchange format. Use the following JavaScript API on an HTML embedded section on a page on the web interface to receive Push Notifications.

Subscribe(event name, callback function name)

Field or Control

Definition

event name

The event to be subscribed to.

callback function name

JavaScript function invoked when the event is published on the server.

Example

<script>
function OnEvent(EventName,EventData)  
 { //EventName is the name of the published event
//EventData is the payload (or data) of the published event in
//JSON(JavaScript Object Notation) form.}
Subscribe("PROCESSSTATUSCHANGE",OnEvent)
</script>

You can also subscribe to events from server runtime itself. This is beneficial for cases when you want to write the published event data to a database table or write to a log file.

Write a PeopleCode handler for subscription of an event, which also acts as the callback method for the event.

Subscription Code

Local object &EventObject;
&EventObject = CreateObject("PSEvent");
SubscriptionHandle = &EventObject.Subscribe("PROCESSSTATUSCHANGE", "PT_PRCS:ProcessMonitor:OnEvent");

The second parameter for the Subscribe method is the fully qualified name of a callback function in the form:

Application Package:Application Class:Function Name

This function is invoked when the event is published.

Syntax of a callback function

 method OnEvent(&EventObject As object);
end-class;

The &EventObject parameter represents the published event data.