Notification Classes Examples

The following are example of typical actions you perform using the notification classes.

See Understanding Notification Templates.

The following example creates a WorklistEntry.

The following is the complete code sample: the steps explain each line.

import PT_WF_WORKLIST:*;

Local WorklistEntry &worklist;

&worklist = create WorklistEntry();

&worklist.busprocname  = "Administer Workflow";
&worklist.busactivity  = "Send Note";
&worklist.buseventname = "Worklist Note";
&worklist.worklistname = "Worklist Note";

If (&worklist.Create() <> 0) Then
   &worklist.oprid = %UserId;
Else
   /* handle error */
End-If;

If (&worklist.Save() <> 0) Then
   /* success, create a corresponding row in */
   /* application worklist record... */
Else
   /* handle error */
End-If;

To create a WorklistEntry:

  1. Import the WorklistEntry class.

    You must import the WorklistEntry class before you can use it in your PeopleCode program. In addition, the second line declares the variable &worklist as type WorklistEntry.

    import PT_WF_WORKLIST:*;
    
    Local WorklistEntry &worklist;
  2. Instantiate a WorklistEntry object.

    Using the constructor, create an instance of the WorklistEntry class. This does not create a WorklistEntry. This creates a WorklistEntry object only. You must use the Create method to actually create the WorklistEntry in the system.

    &worklist = create WorklistEntry();
  3. Set the required parameters.

    Some of the WorklistEntry class properties are required for every WorklistEntry. You must set a value for these properties before you can update or save the WorklistEntry.

    &worklist.busprocname  = "Administer Workflow";
    &worklist.busactivity  = "Send Note";
    &worklist.buseventname = "Worklist Note";
    &worklist.worklistname = "Worklist Note";
  4. Create the WorklistEntry.

    After you've set the required values, you need to create the WorklistEntry in the system. This does not update the database. This does, however, add values to the notification tables.

    If this method completes successfully, the following properties are populated: instanceid and transactionid.

    • instanceid

    • transactionid

      If (&worklist.Create() <> 0) Then
         &worklist.oprid = %Userid;
      Else
         /* handle error */
      End-If;
  5. Save the WorklistEntry.

    After you've created the WorklistEntry, save it. The Save method actually updates the database, and so can be used only in events that allow database updates.

    If (&worklist.Save() <> 0) Then
       /* success, create a corresponding row in */
       /* application worklist record... */
    Else
       /* handle error */
    End-If;

The following example updates a WorklistEntry so that it is considered worked.

The following is the complete code sample: the steps explain each line.

import PT_WF_WORKLIST:*;

Local WorklistEntry &worklist;

&worklist = create WorklistEntry();
&worklist.busprocname = "Administer Workflow";
&worklist.busactivity = "Send Note";
&worklist.buseventname = "Worklist Note";
&worklist.worklistname = "Worklist Note";
&worklist.instanceid = 2;

&ret = &worklist.SelectByKey();

&worklist.inststatus = "2"; /* mark entry worked */
If (&worklist.Update() <> 0) Then
   If (&worklist.Save() <> 0) Then
      /* success */
   Else
      /* handle error */
   End-If;
Else
   /* handle error */
End-If;

To update a WorklistEntry:

  1. Import the WorklistEntry class.

    You must import the WorklistEntry class before you can use it in your PeopleCode program. In addition, the second line declares the variable &worklist as type WorklistEntry.

    import PT_WF_WORKLIST:*;
    
    Local WorklistEntry &worklist;
  2. Instantiate a WorklistEntry object.

    Using the constructor, create an instance of the WorklistEntry class. This does not create a WorklistEntry. This creates a WorklistEntry object only. You must use the Create method to actually create the WorklistEntry in the database tables, and the Save method to update the tables.

    &worklist = create WorklistEntry();
  3. Set the required parameters.

    Some of the WorklistEntry class properties are required for every WorklistEntry. You must set a value for these properties before you can update or save the WorklistEntry. The instanceid property, combined with the other properties, indicates a unique WorklistEntry. This value is populated after a WorklistEntry has already been created.

    &worklist.busprocname  = "Administer Workflow";
    &worklist.busactivity  = "Send Note";
    &worklist.buseventname = "Worklist Note";
    &worklist.worklistname = "Worklist Note";
    &worklist.instanceid = 2;
  4. Populate the worklist entry with data.

    After you've set the keys, populate the worklist entry based on those keys using the SelectByKey method.

    &ret = &worklist.SelectByKey();
  5. Update and save the WorklistEntry.

    After you've set the required parameters, try to update the WorklistEntry. If that is successful, mark the WorklistEntry as 'worked', and try to save the WorklistEntry. The Save method actually updates the database, and so can be used only in events that allow database updates.

    If (&worklist.Update() <> 0) Then
       &worklist.inststatus = "2"  /* mark entry worked */
       If (&worklist.Save() <> 0) Then
          /* success */
       Else
          /* handle error */
       End-If;
    Else
          /* handle error */
    End-if;