Publishing an Event

You can publish an event from server runtime using the PeopleCode APIs provided by the framework. The procedure depends on the data type: KeyValue or PeopleCode rowset.

If you are publishing an event where the data type is a KeyValue pair you follow these general steps:

  1. Set values for the keys defined for the event.

  2. Add a recipient user who has subscribed to the event.

    Note: Adding recipients to the event is optional. If you add users or roles using the APIs as recipients then the recipients added through web interface while defining the event are ignored.

  3. Publish the event.

Example

This example demonstrates the publishing of the event PROCESSSTATUSCHANGE with the keys PROCESSID and RUNSTATUS and recipient user, VP1.

  1. Create the event object.

    Local object &EventObject;
    &EventObject = CreateObject("PSEvent");
    
  2. Set values for the keys defined in the event

    &EventObject.SetKeyValuePair("PROCESSID", PSPRCSSTATUS.PROCESSID);
    &EventObject.SetKeyValuePair("STATUS", PSPRCSSTATUS.RUNSTATUS);
    
  3. (Optional) Add a recipient user for the event.

    In this case, the event will be sent only to user VP1 (if VP1 has subscribed to the event).

    &EventObject.AddRecipient("VP1", 1)

    The the parameters for AddRecipient are:

    Field or Control

    Definition

    recipient

    Specify the recipient using either a user name or a role name.

    recipient type

    Use a value of 1 to indicate a user.

    Use a value of 2 to indicate a role.

  4. Publish the event.

    &EventObject.Publish("PROCESSSTATUSCHANGE");

If the data type is PeopleCode rowset, you set the values for the fields in the record and add a recipient.

Example

This example illustrates publishing an event for a PeopleCode rowset. In this example, WORKFLOWAPPROVAL is the server event for which name and status fields are defined. All users assigned the role of Workflow Administrator are added as recipients.

  1. Create the event object.

    Local object &EventObject;
    &EventObject = CreateObject("PSEvent");
    
  2. Set the PeopleCode Rowset for the event.

    Local object &EventObject;
    &rs = CreateRowset(Record.PSPTWKLAPPVL);
    &rs.InsertRow(&i);
    &rs(&i).PSPTWKLAPPVL.NAME.Value = "Test Workflow";
    &rs(&i).PSPTWKLAPPVL.STATUS.Value = 1;
    &EventObject.SetRowsetData(&rs);
    
  3. (Optional) Add a recipient role for the event.

    In this case, the event will be sent only to users who have subscribed to the event and belong to the role: Workflow Administrator.

    &EventObject.AddRecipient("Workflow Administrator", 2);
  4. Publish the event.

    &ret = &EventObject.publish("WORKFLOWAPPROVAL");