Example: Setting Up a Workflow to Use with the Process Manager

The person who sets up a workflow task in the Process Manager form adds a task with Task Type set to Start a Workflow, specifies information about the task, and then selects the workflow event in the Event Name field. The Event Name field lists all non-framework, non-core events that are available in SyteLine. You must create the workflow events that will be listed here.

When the person assigned to the workflow task opens the task in the Process Manager, the name of the event is displayed in the Event Name field. The person clicks the Initiate Event button to start the workflow.

The HR_NewHireAnnouncement event and its event handler, as well as some event actions and a sample stored procedure, are provided in the initialized database, as an example workflow for you to modify and then test in the Process Manager. This sample workflow sends a notification to all employees that provides the new hire's name and position details. You must edit this example as described here if you want to test it in your system. The example shows how to pass parameters through form scripting for this event. The generic stored procedure fires any given custom event.

Event Definition

This sample HR_NewHireAnnouncement event has a handler and three event actions:

  • Action Type "Set Attributes" SET(EVENTTITLE=E(EventTitle)): This event action writes the process task RowPointer to the event title for cross-reference purposes.
  • Action Type "Notify" has these parameters:
    • To: Event Global Constant "HRNewHireAnnouncementRecipients"
      Note: You must define the list of associated users for this Event Global Constant.
    • Subject: Translatable string "Welcoming new Employee <empname>"
    • Body: Translatable string "I am very pleased to announce that <empname> will be joining us as <empposition> from today."

    This event action notifies users who are associated with the Event Global Constant about the new hire. EmpName and EmpPosition are the input parameters for this event. That information is taken from the process where this workflow originates.

  • Action Type: "Finish"

If you want to write your own events, you must use the first and third event actions, and write your own event actions in between, based on your requirements.

The sample HR_NewHireAnnouncement event is delivered as inactive. You must activate it on the Workflow Event Handler Activation form in order to use it. In the Notify Users field, specify the appropriate users who should receive the New Hire Announcement notification.

Form Scripting:

  • For all custom events that must be supported by the Process Manager, identify any input parameters that are required. (The example HR_NewHireAnnouncement event requires two input parameters: EmpName and EmpPosition).
  • If an event uses input parameters, determine whether those input parameter values can be retrieved from the form page components, properties, or variables. If not, retrieve those values on the form. Assign those Input parameters. (For our example, both of the input parameters' data can be retrieved from the form components.)

    Assign input parameters, as shown in our example:

    
    If ThisForm.Components("MyTasksFormPageEventNameEdit").Text = "HR_NewHireAnnouncement" Then
              ThisForm.Variables("ParmName1").Value = "EmpName"
              ThisForm.Variables("ParmValue1").Value = ThisForm.Components("MyTasksFormPageEmpName1Edit").Text
              ThisForm.Variables("ParmName2").Value = "EmpPosition"
              ThisForm.Variables("ParmValue2").Value = ThisForm.Components("MyTasksFormPageJobTitleEdit").Text
    End If
    Note:  If you want to execute additional custom HR events from the Process Manager, add your own block of code in the Process Manager form scripting to assign input parameters for your custom events. We provide the example code as a framework that you can build on.
  • Run the stored procedure with the event name available on the form, along with all of the name/value pairs that are supported by the stored procedure.

Stored Procedure

We provide a generic stored procedure GenericNotifyEventGlobalCsSp with these parameters:

  • @EventName
  • @ProcessTaskRowPointer
  • @EventStateRowPointer OUTPUT
  • @Infobar OUTPUT
  • @ParmName1
  • @ParmValue1
  • @ParmName2
  • @ParmValue2
  • €¦etc for Parm Names and Values 3 to 19 ...
  • @ParmName20
  • @ParmValue20

The stored procedure performs these steps:

  • Initialize @SessionId, @EventTrxId, @EventParmId
  • Pass @ProcessTaskRowPointer as input parameter to the Event, which is stored in the "Event Title"
  • Execute FireEventSp by passing the @EventName, @SessionId, @EventTrxId and @EventParmId
  • WAITFOR DELAY '00:00:05'
  • Read the Event State RowPointer and return to the form.
Note:  Depending on the setting of the "Keep Successful Event States" option on the Process Defaults form, an EventState record might not be created if the event was successful. In that case, EventStateRowPointer is NULL, which is not a problem, since you only want to catch any failed events.

When the example code is updated as specified here, and the Initiate Event button is clicked in the Process Manager form, the created Event Status record's RowPointer is stored in process_mgr_process_task.EventStateRowPointer.  The success message is displayed as "Event was initiated."