PSEvent Class Methods

In this section, the PSEvent class methods are presented in alphabetical order.

Syntax

AddRecipient(name, type)

Description

Use the AddRecipient method to set a specific recipient to receive the notification. Either a user ID or a role name can be specified, but not both.

Note: If no recipients are set for a notification, all the users who have subscribed for that notification will receive the notification.

Parameters

Field or Control

Definition

name

A string representing the name of the recipient (user ID or role name).

type

A number representing the type of the recipient:

  • 1 — If the name parameter represents a user ID.

  • 2 — If the name parameter represents a role name.

Returns

A Boolean value: True if the method completes successfully, False otherwise.

Example

The following example sets the user PTUSER as the recipient.

&name = "PTUSER";
&EventObject.AddRecipient(&name, 1);

Syntax

AddRecipients(names, type)

Description

Use the AddRecipients method to set multiple recipients to receive the notification. Either user IDs or a role names can be specified, but not both.

Parameters

Field or Control

Definition

names

A string array representing the name of the recipients (either user IDs or role names).

type

A number representing the type of the recipients:

  • 1 — If the names parameter represents user IDs.

  • 2 — If the names parameter represents role names.

Returns

A Boolean value: True if the method completes successfully, False otherwise.

Example

The following example sets an array of user IDs as the recipients.

Local array of string &USERIDS;
Local string &ROLENAME;

&ROLENAME = "Portal Administrator";
Local Rowset &rs = CreateRowset(Record.PSROLEUSER);
&rs.Fill("WHERE ROLENAME=:1", &ROLENAME);
&USERIDS = CreateArrayRept("", 0);
For &i = 1 To &rs.RowCount
   &USERIDS.Push(&rs(&i).PSROLEUSER.ROLEUSER.Value);
End-For;

&EventObject.AddRecipients(&USERIDS, 1);

Syntax

GetRecipients(type)

Description

Use the GetRecipients method to get all the recipients of a particular type from the notification.

Parameters

Field or Control

Definition

type

A number representing the type of recipients:

  • 1 — For user IDs.

  • 2 — For role names.

Returns

An array of string representing the recipients for the specified type.

Example

The following example retrieves all role-type recipients:

Local array of string &RoleNames;
&type = 2;
RoleNames= &EventObject.GetRecipients(&type);

Syntax

GetRowSetData()

Description

Use the GetRowSetData method to get the rowset data from the notification.

Parameters

None.

Returns

A Rowset object.

Example

The following example retrieves the rowset data.

Local Rowset &oRowset;
&oRowset = &EventObject.GetRowSetData();

Syntax

GetValueOfKey(key)

Description

Use the GetValueOfKey method to get the value for a key from the notification data.

Parameters

Field or Control

Definition

key

Specify the string representing the name of the key. Key names are defined in the Data Structure field on the Define Server Side Events page.

Returns

A valid string representing the corresponding value for the key, if the key exists. An empty string if the key does not exist.

Example

The following example gets the value for the key named ID.

&Key = "ID";
&Value = &EventObject.GetValueOfKey(&Key);

Syntax

Publish(event_name)

Description

Use the Publish method to publish a notification for an event.

Parameters

Field or Control

Definition

event_name

A string representing the name of the event as defined on the Define Server Side Events page.

Returns

A Boolean value: True if the method completes successfully, False otherwise.

Example

The following example uses a method definition to set event data and then publish a notification named WORKFLOWAPPROVAL.

method SendApprovalNotification
	/+ &category as String, +/
	/+ &message as String, +/
	/+ &actionsLink as String, +/
	Local object &EventObject;

	&EventObject = CreateObject("PSEvent");
	&EventObject.SetKeyValuePair("CATEGORYNAME", &category);
	&EventObject.SetKeyValuePair("MESSAGE", &message);
	&EventObject.SetKeyValuePair("ACTIONSLINK", &actionsLink);
	&EventObject.Publish("WORKFLOWAPPROVAL");
end-method;

Syntax

RemoveRecipients(type)

Description

Use the RemoveRecipients method to remove all the recipients of a particular type from the notification.

Parameters

Field or Control

Definition

type

A number representing the type of recipients:

  • 1 — For user IDs.

  • 2 — For role names.

Returns

None.

Example

The following example removes recipients of type "role names" from the notification.

&type = 2;
&EventObject.RemoveRecipients(&type);

Syntax

SetKeyValuePair(key, value)

Description

Use the SetKeyValuePair method to add data in the form key-value pair to the notification.

Note: Notification data can be represented as either key-value pairs or as a rowset, not both. The event definition on the Define Server Side Events page determines the type of data for the notification and therefore the Setxxx method to be used.

Parameters

Field or Control

Definition

key

Specify the string representing the name of the key. Key names are defined in the Data Structure field on the Define Server Side Events page.

value

Specify the string representing the value.

Returns

A Boolean value: True if the method completes successfully, False otherwise.

Example

The following example sets the value for the key named "ID".

&Key = "ID";
&Value = "100";
&EventObject.SetKeyValuePair(&Key, &Value);

Syntax

SetRowSetData(&rowset)

Description

Use the SetRowSetData method to set a Rowset object as the data for the notification.

Note: Notification data can be represented as either key-value pairs or as a rowset, not both. The event definition on the Define Server Side Events page determines the type of data for the notification and therefore the Setxxx method to be used.

Parameters

Field or Control

Definition

&rowset

An already instantiated Rowset object, which acts as the notification data.

Returns

A Boolean value: True if the method completes successfully, False otherwise.

Example

The following example sets rowset data from the QE_CHART_RECORD record.

Local Rowset &oRowset;
&oRowset = CreateRowset(Record.QE_CHART_RECORD);
&oRowset.Fill("where QE_CHART_REGION= :1", "MIDWEST");
&EventObject.SetRowSetData(&oRowset);

Syntax

Subscribe(event_name, callback_method)

Description

Use the Subscribe method to have the PeopleCode program running on the application server subscribe to a notification for an event. Alternatively, JavaScript provides different mechanisms for subscribing to a notification for an event from a PeopleSoft page.

Parameters

Field or Control

Definition

event_name

A string representing the name of the event as defined on the Define Server Side Events page.

callback_method

A string value representing the method to be invoked when the notification is received by the subscriber.

The string must be a fully qualified method name in the form:

APP_PKG:App_Class:Method_Name

Returns

A Boolean value: True if the method completes successfully, False otherwise.

Example

The following example subscribes to a notification named PROCESSSTATUSCHANGE:

&EventObject.Subscribe("PROCESSSTATUSCHANGE", "PT_PRCS:ProcessMonitor:OnProcessStatusChange");

This example requires the implementation of a callback method named OnProcessStatusChange in the PT_PRCS:ProcessMonitor application class:

class ProcessMonitor
	method OnProcessStatusChange(&EventObject As object);
end-class;
method OnProcessStatusChange
  /+ &EventObject as Object +/
  Local string &ID;
	Local string &PROCESSNAME;
	Local string &KEY;

	&KEY = "ID";
	&ID = &EventObject.GetValueOfKey(&KEY);

	&KEY = "PROCESSNAME";
	&PROCESSNAME = &EventObject.GetValueOfKey(&KEY);
end-method;

Syntax

Unsubscribe(event_name)

Description

Use the Unsubscribe method to unsubscribes from a notification for an event..

Parameters

Field or Control

Definition

event_name

A string representing the name of the event as defined on the Define Server Side Events page.

Returns

None.

Example

The following example unsubscribes from a notification named PROCESSSTATUSCHANGE.

&eventName = "PROCESSSTATUSCHANGE";
&EventObject.Unsubscribe(&eventName);