Software to help you build a better store
SEARCH
November 3, 2006

How to Create a BVC5 Order Workflow Task

Several workflow tasks are included in BVC5 to perform work such as sending an email or marking the order complete. When I test Shipper Service for BVC5 I want to make sure that the appropriate workflows are run. Setting breakpoints in a debugger works but is very tedious. So I created the "Add Order Note" task and put it at the beginning of each workflow I was tracking. After processing a shipment, I can display the order details and see at a glance which workflows were run and in what order. This article describes how to create the "Add Order Note" workflow task.

The "Add Order Note" task has two parts: the task processor and the task editor. Some tasks such as "Update Order" have no settings and no need for an editor. Tasks like "Add Order Note" can be customized and therefore have an editor.

Creating the Task Processor

An order task is pretty straightforward. Create a new class in your web site's App_Code directory that inherits from BVSoftware.Bvc5.Core.BusinessRules.OrderTask. At the very least the task must override the Clone, Execute, Rollback, TaskId, and TaskName methods. The "Add Order Note" task also overrides the StepName method so that we can give the step a unique name within a workflow.

Figure 1. AddOrderNote.vb
Imports BVSoftware.Bvc5.Core
Imports BVSoftware.Bvc5.Core.BusinessRules
Imports BVSoftware.Bvc5.Core.Orders
 
Public Class AddOrderNote
    Inherits OrderTask
 
    Public Overrides Function Clone() _
        As BVSoftware.Bvc5.Core.BusinessRules.Task
 
        Return New AddOrderNote
 
    End Function
 
    Public Overloads Overrides Function Execute( _
        ByVal context As OrderTaskContext) _
        As Boolean
 
        Try
            Dim note As New OrderNote()
            If Me.SettingsManager.GetBooleanSetting("Private", True) Then
                note.NoteType = OrderNoteType.Private
            Else
                note.NoteType = OrderNoteType.Public
            End If
            note.Note = Me.SettingsManager.GetSetting("Note", "<empty>")
            If context.Order.AddNote(note) Then
                Return True
            Else
                context.Errors.Add( _
                    New WorkflowMessage("Add Note Failed", _
                        "Add note failed for order " & context.Order.OrderNumber, _
                        False))
                Return False
            End If
        Catch ex As Exception
            context.Errors.Add( _
                New WorkflowMessage("Add Note Failed", _
                    "Add note failed for order " _
                    & context.Order.OrderNumber _
                    & ". " & _
                    ex.Message, _
                    False))
            Return False
        End Try
    End Function
 
    Public Overloads Overrides Function Rollback( _
        ByVal context As OrderTaskContext) _
        As Boolean
 
        Return True
 
    End Function
 
    Public Overrides Function TaskId() As String
 
        Return "26AE4A5B-F20A-4B96-AA45-95A546E62BA3"
 
    End Function
 
    Public Overrides Function TaskName() As String
 
        Return "Add Order Note"
 
    End Function
 
    Public Overrides Function StepName() As String
 
        Return Me.SettingsManager.GetSetting("StepName", Me.TaskName)
 
    End Function
 
End Class

Creating the Task Editor

As you can see in Figure 1, the "Add Order Note" task has three settings: "Note", "Private", and "StepName". The Task Editor is used to edit those settings. To create the editor, first make a new folder in BVModules/OrderTasks with the same name as the task ("Add Order Note"). Next create a new Web User Control called Edit.ascx that inherits from BVSoftware.Bvc5.Core.Content.BVModule. The editor should be coded to display and save the "Note", "Private", and "StepName" settings and then call the NotifyFinishedEditing() when done.

Figure 2. Edit.ascx
<%@ Control 
    AutoEventWireup="false" 
    CodeFile="Edit.ascx.vb" 
    Inherits="BVModules_OrderTasks_Add_Order_Note_Edit"
    Language="VB"
%>
<table border="0" cellspacing="0" cellpadding="3">
<tr>
    <td class="formlabel">
        <asp:Label ID="StepNameLabel" runat="server" 
            AssociatedControlID="StepNameField" 
            Text="Step Name:" />
        </td>
    <td class="formfield">
        <asp:TextBox ID="StepNameField" runat="server" />
    </td>
</tr>
<tr>
    <td class="formlabel">
        <asp:Label ID="PrivateFieldLabel" runat="server" 
            AssociatedControlID="PrivateField" 
            Text="Private:" />
    </td>
    <td class="formfield">
        <asp:CheckBox ID="PrivateField" runat="server" />
    </td>
</tr>
<tr>
    <td class="formlabel">
        <asp:Label ID="NoteLabel" runat="server" 
            AssociatedControlID="NoteField" 
            Text="Note:" />
    </td>
    <td class="formfield">
        <asp:TextBox ID="NoteField" runat="server" 
            TextMode="MultiLine" />
    </td>
</tr>
<tr>
    <td class="formlabel">
        <asp:ImageButton ID="btnCancel" runat="server" 
            CausesValidation="false" 
            ImageUrl="~/BVAdmin/Images/Buttons/Cancel.png" />
    </td>
    <td class="formfield">
        <asp:ImageButton ID="btnSave" runat="server" 
            ImageUrl="~/BVAdmin/Images/Buttons/SaveChanges.png" />
    </td>
</tr>
</table>
Figure 3. Edit.ascx.vb
Imports BVSoftware.Bvc5.Core
Imports BVSoftware.Bvc5.Core.Content
 
Partial Class BVModules_OrderTasks_Add_Order_Note_Edit
    Inherits BVModule
 
    Protected Sub Page_Load(ByVal sender As Object, _
        ByVal e As System.EventArgs) _
        Handles Me.Load
 
        If Not Page.IsPostBack Then
            DataBind()
        End If
 
    End Sub
 
    Protected Sub btnCancel_Click(ByVal sender As Object, _
        ByVal e As System.Web.UI.ImageClickEventArgs) _
        Handles btnCancel.Click
 
        MyBase.NotifyFinishedEditing()
 
    End Sub
 
    Protected Sub btnSave_Click(ByVal sender As Object, _
        ByVal e As System.Web.UI.ImageClickEventArgs) _
        Handles btnSave.Click
 
        SaveData()
        Me.NotifyFinishedEditing()
 
    End Sub
 
    Public Overrides Sub DataBind()
        MyBase.DataBind()
        Me.StepNameField.Text = Me.SettingsManager.GetSetting("StepName", String.Empty)
        Me.PrivateField.Checked = Me.SettingsManager.GetBooleanSetting("Private", True)
        Me.NoteField.Text = Me.SettingsManager.GetSetting("Note", String.Empty)
    End Sub
 
    Private Sub SaveData()
        Me.SettingsManager.SaveSetting("StepName", _
            Me.StepNameField.Text.Trim, _
            "Structured Solutions", _
            "Order Tasks", _
            "Add Order Note")
        Me.SettingsManager.SaveBooleanSetting("Private", _
            Me.PrivateField.Checked, _
            "Structured Solutions", _
            "Order Tasks", _
            "Add Order Note")
        Me.SettingsManager.SaveSetting("Note", _
            Me.NoteField.Text.Trim, _
            "Structured Solutions", _
            "Order Tasks", _
            "Add Order Note")
    End Sub
End Class

Add the Task to TaskLoader

The last step is to add the task to TaskLoader.vb.

Figure 4. Partial TaskLoader.vb
Public Shared Function LoadOrderTasks() As Collection(Of BusinessRules.OrderTask)
    Dim result As New Collection(Of BusinessRules.OrderTask)
    result.Add(New AddOrderNote)

Using the Task

Follow these steps to add the new "Add Order Note" task to a workflow:

  1. Select Options > Workflow from the BV Admin menu
  2. Click on the Edit link next to a workflow.
  3. Select "Add Order Note" and then click on the New button.
  4. Click on the Edit button next to the new "Add Order Note" task.
  5. Enter a task name.
  6. Check Private if you want a private note or leave it unchecked if you want a public note.
  7. Enter the text of the Note.
  8. Click on the Save Changes button.
  9. Click on the OK button.

Now every time the workflow is run, your note will be added to the order.

This site looks much better in a browser that supports current web standards, but it is accessible to any browser. Download one now This link is to a third party web site which will open in a new window

Some parts of this site will not work effectively on this older browser.
Please consider updating your browser This link is to a third party web site which will open in a new window

SSL