How to create initial and start views for a workflow

From Sense/Net Wiki
Jump to: navigation, search
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned


You can use many different types of workflows in Sense/Net. See the Workflow page for more information on how Sense/Net and Windows Workflow Foundation can cooperate. On this page you can learn how to create the two necessary content views for the workflow to operate correctly: Initial view and Start view. These content views are created for the workflow type, in this case we build them for the Approval workflow content type.


In this section I will show you how to create initial and start views for workflows and where should you place them.

1. Create the initial view

In Sense/Net you can define two types of workflows: Content workflow or Standalone workflow (for more information please check the Workflow types article). In case of a Content workflow you have to define an initial content view that will be displayed to the user who assigns the workflow to a Content List. This content view should be named as AssignWorkflow.ascx and placed into the content view folder of the workflow type. In this case, we place this to the /Root/Global/contentviews/ApprovalWorkflow folder.

Note that in case of a Standalone workflow you do not have to create an initial view because it will not be assigned to a Content List.

The initial view contains the fields that drive the approval process: first and second level approvers and time frames for approving the document. These fields will be filled by the list admin who assigns the workflow to the list (and not the users who start the workflow). For more information about creating content views see the Content View sample page.

<%@ Language="C#" AutoEventWireup="true" Inherits="SenseNet.Portal.UI.SingleContentView" %>
<div class="sn-content sn-content-inlineview">
    <sn:GenericFieldControl runat="server" ID="GenericFieldcontrol1" FieldsOrder="DisplayName Description FirstLevelApprover FirstLevelTimeFrame SecondLevelApprover SecondLevelTimeFrame WaitForAll" />        
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<div class="sn-panel sn-buttons">
  <asp:Button class="sn-submit" ID="AssignWorkflow" runat="server" Text="Assign to list" />
  <sn:BackButton class="sn-submit" ID="Cancel" runat="server" Text="Cancel" />

Note that the ID of the button that assigns the workflow to the Content List should be AssignWorkflow. If this control is not present in the content view, the assign workflow portlet will not be able to connect the workflow to the list.

After you saved this content view users will be able to assign the Approval workflow to a content list.

Assign workflow to list

2. Create the start view

The Start view is displayed to the user when he/she starts the workflow. This content view is necessary for all types of workflows to function correctly. The name of this content view is StartWorkflow.ascx and it should be placed to the content view folder of the workflow type. In this case the view will be /Root/Global/contentviews/ApprovalWorkflow/StartWorkflow.ascx.

The start view for the Approval workflow does not contain any editable fields. It displays only the approver users and time frames the administrator chose when he/she assigned the workflow to this list. If there are any values that the user should fill at this point (for example comments for the approver), it should be placed into this view.

The following sample view contains some logic about calculating time frames but basically only displays the names of the approver users and the time frame they have.

<%@ Language="C#" AutoEventWireup="true" Inherits="SenseNet.Portal.UI.SingleContentView" %>
<%@ Import Namespace="SenseNet.ContentRepository" %>
<%@ Import Namespace="SenseNet.ContentRepository.Storage" %>
<div class="sn-content sn-workflow sn-content-inlineview">
            var FirtsLevelApprover = this.Content["FirstLevelApprover"] as IEnumerable<Node>;
            string FirstLevelTimeFrame = String.Format("{0} hours", TimeSpan.Parse(this.Content["FirstLevelTimeFrame"].ToString()).TotalHours);
            var SecondLevelApprover = this.Content["SecondLevelApprover"] as IEnumerable<Node>;
            string SecondLevelTimeFrame = String.Format("{0} hours", TimeSpan.Parse(this.Content["SecondLevelTimeFrame"].ToString()).TotalHours);
        <h2 class="sn-content-title"><%= SenseNet.Portal.UI.IconHelper.RenderIconTag(this.Icon, null, 32) %>Start <strong><%= (this.Content.ContentHandler as GenericContent).DisplayName%></strong> on <strong><%= ((Node)this.Content["RelatedContent"]).DisplayName %></strong></h2> 
        <dl class="sn-content-lead">
        <% if (FirtsLevelApprover != null && FirtsLevelApprover.Count() > 0) { %> <dt>First level approver:</dt><dd><strong> <%= FirtsLevelApprover.FirstOrDefault().DisplayName %> </strong></dd><% } %>
        <% if (!String.IsNullOrEmpty(FirstLevelTimeFrame)) { %> <dt>First level time frame:</dt><dd><strong><%= FirstLevelTimeFrame %> </strong></dd><% } %>
        <% if (SecondLevelApprover != null && SecondLevelApprover.Count() > 0) { %>
        <dt>Second level approver(s):</dt><dd>
            <% foreach (var approver in SecondLevelApprover)
               { %> 
               <strong> <%= approver.DisplayName %> </strong> &nbsp;
            <% } %></dd> 
        <% } %>
        <% if (!String.IsNullOrEmpty(SecondLevelTimeFrame)) { %> <dt>Second level time frame:</dt><dd><strong> <%= SecondLevelTimeFrame %> </strong></dd><% } %>
<sn:ErrorView id="ERROR"  runat="server" />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
<div class="sn-panel sn-buttons">
  <asp:Button class="sn-submit" ID="StartWorkflow" runat="server" Text="START" />

Note that the ID of the button that starts the workflow should be StartWorkflow. If this control is not present in the content view, the start workflow portlet will not be able to start the workflow.

If you placed the content view to the place given above, the following page will be displayed to the users when they start the approval workflow on a document:

Start the approval workflow


Related links