Datapolis Process System SDK

Search:

Contents
:
IndexBookmarkPrint
Home > Custom Forms > Creating Custom Form Walkthrough

Creating Custom Form Walkthrough

 

 

This walkthrough will guide you through creating a custom form. The form consists of textbox with label and action launch button.

​

Prerequisites


Before creating a custom control, be sure you have installed all of the necessary components.
  1. Open a new Visual Studio project (File | New | Project)
  2. Create a new SharePoint 2013 - empty project.
  3. Name the project appropriately. In this case it might be WorkboxCustomForm. Set the other project properties (Location, Solution Name etc.)
  4. Select project to be deployed as farm solution and choose right site for debugging.
  5. Add reference to Datapolis.WorkBox.Common  - it should be available in GAC.
  6. Add reference to Datapolis.WorkBox.Utilities - you can download it here [ Link in development ]

Add application page


Firstly add Layouts mapped folder to solution.

 

 

Then to Layouts folder add new item.

 

 

Choose Application page and add new form. In this example it will be named WorkboxCustomForm.aspx.

 

 

New empty application page has been created. This page will be used later as our action form.

 

Develop control


Add following lines to WorkboxCustomForm.aspx to define control's look. In this example will be added simple label and textbox to provide parameter to action. You can add more or even generate them dynamically basing on data provided in action parameters collection.

 

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
</asp:Content>
 
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
 
    <asp:Label ID="lblSomeParameter" Text="Some parameter" runat="server"></asp:Label>
    <asp:TextBox ID="tbxSomeParameter" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="btnLaunchAction" runat="server" Text="Launch action" />
 
</asp:Content>
 
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    Workbox Custom Form
</asp:Content>
 
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
    Workbox Custom Form
</asp:Content>

 

Edit code behind


Open WorkboxCustomForm.aspx.cs file. It should look like below. Add using statement for Datapolis.WorkBox.Common namespace.

 

using System;
using Microsoft.SharePoint;
using Datapolis.WorkBox.Common.Security;
 
namespace WorkboxCustomForm.Layouts.WorkboxCustomForm
{
    public partial class WorkboxCustomForm : LayoutsPageBase
    {
       
    }
}

 

Now add parsing of form parameters. When you choose a custom form to be used as an action form then several parameters will be added to url when user clicks action and workflow redirects to your page. Those parameters describes the action. You need to parse those parameters to check which action and in which workflow the form should show.

 

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Datapolis.WorkBox.Common.Security;
  
namespace WorkboxCustomForm.Layouts.WorkboxCustomForm
{
    public partial class WorkboxCustomForm : LayoutsPageBase
    {
        #region Private Fields
  
        private Guid _listID;
        private Guid _workflowID;
        private int _itemID;
        private string _actionName;
        private string _sourceUrl;
        private string _redirectUrl;
  
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            #region Request parameters
            try
            {
                _listID = new Guid(Page.Request["List"]);
            }
            catch(Exception ex)
            {
                throw new Exception("List parameter was not recognized", ex);
            }
            try
            {
                _workflowID = new Guid(Page.Request["workflowID"]);
            }
            catch(Exception ex)
            {
                throw new Exception("WorkflowID parameter was not recognized.", ex);
            }
            try
            {
                if (!string.IsNullOrEmpty(Page.Request["ItemID"]))
                    _itemID = int.Parse(Page.Request["ItemID"]);
                else
                    _itemID = -1;
            }
            catch(Exception ex)
            {
                throw new Exception("WorkflowID parameter was not recognized", ex);
            }
            _actionName = Page.Request["ActionName"];
            _sourceUrl = Page.Request["SourceUrl"];
            _redirectUrl = Page.Request["RedirectUrl"];
            #endregion
        }
    }
}
 

Now we will add fields containing WBInterface classes. Those object contains WBInterface manager class and action and its parameter.

 

#region Private Fields
 
private Guid _listID;
private Guid _workflowID;
private int _itemID;
private string _actionName;
private string _sourceUrl;
private string _redirectUrl;
 
Datapolis.WorkBox.Common.WBInterface.WBInterfaceManager _interfaceManager;
Datapolis.WorkBox.Utilities.WBInterface.WBWorkflowInfo _workflowInfo;
Datapolis.WorkBox.Utilities.WBInterface.WBActionInfo _actionInfo;
Datapolis.WorkBox.Utilities.WBInterface.WBActionParameter _actionParameter;
 
#endregion

 

Then in Load page method interface manager will be opened and action will be loaded. Also textbox will be filled with data from action parameter.

 

protected void Page_Load(object sender, EventArgs e)
       {
           #region Request parameters
           try
           {
               _listID = new Guid(Page.Request["List"]);
           }
           catch(Exception ex)
           {
               throw new Exception("List parameter was not recognized", ex);
           }
           try
           {
               _workflowID = new Guid(Page.Request["workflowID"]);
           }
           catch(Exception ex)
           {
               throw new Exception("WorkflowID parameter was not recognized.", ex);
           }
           try
           {
               if (!string.IsNullOrEmpty(Page.Request["ItemID"]))
                   _itemID = int.Parse(Page.Request["ItemID"]);
               else
                   _itemID = -1;
           }
           catch(Exception ex)
           {
               throw new Exception("WorkflowID parameter was not recognized", ex);
           }
           _actionName = Page.Request["ActionName"];
           _sourceUrl = Page.Request["SourceUrl"];
           _redirectUrl = Page.Request["RedirectUrl"];
 
           #endregion
           #region Fill parameter
 
           _interfaceManager = new Datapolis.WorkBox.Common.WBInterface.WBInterfaceManager(SPContext.Current.Web);
           _interfaceManager.GetWBSiteInfo();
           _workflowInfo = _interfaceManager.GetWBWorkflowInfo(_workflowID);
           _actionInfo = _workflowInfo.WorkflowActions[_actionName];
           _actionParameter = _actionInfo.Parameters["SomeParameter"];
           if(_actionParameter != null)
           {
               tbxSomeParameter.Text = _actionParameter.Properties["DefaultValue"].ToString();
           }
 
           #endregion
 
       }

  

Next fill button click event. In this event text provided in textbox is written to action parameter value. Then action is launched and page is redirected.

 

public partial class WorkboxCustomForm : LayoutsPageBase
 {
     #region Private Fields
 
     private Guid _listID;
     private Guid _workflowID;
     private int _itemID;
     private string _actionName;
     private string _sourceUrl;
     private string _redirectUrl;
 
     Datapolis.WorkBox.Common.WBInterface.WBInterfaceManager _interfaceManager;
     Datapolis.WorkBox.Utilities.WBInterface.WBWorkflowInfo _workflowInfo;
     Datapolis.WorkBox.Utilities.WBInterface.WBActionInfo _actionInfo;
     Datapolis.WorkBox.Utilities.WBInterface.WBActionParameter _actionParameter;
 
     #endregion
     protected void Page_Load(object sender, EventArgs e)
     {
         #region Request parameters
         try
         {
             _listID = new Guid(Page.Request["List"]);
         }
         catch(Exception ex)
         {
             throw new Exception("List parameter was not recognized", ex);
         }
         try
         {
             _workflowID = new Guid(Page.Request["workflowID"]);
         }
         catch(Exception ex)
         {
             throw new Exception("WorkflowID parameter was not recognized.", ex);
         }
         try
         {
             if (!string.IsNullOrEmpty(Page.Request["ItemID"]))
                 _itemID = int.Parse(Page.Request["ItemID"]);
             else
                 _itemID = -1;
         }
         catch(Exception ex)
         {
             throw new Exception("WorkflowID parameter was not recognized", ex);
         }
         _actionName = Page.Request["ActionName"];
         _sourceUrl = Page.Request["SourceUrl"];
         _redirectUrl = Page.Request["RedirectUrl"];
 
         #endregion
         #region Fill parameter
 
         _interfaceManager = new Datapolis.WorkBox.Common.WBInterface.WBInterfaceManager(SPContext.Current.Web);
         _interfaceManager.GetWBSiteInfo();
         _workflowInfo = _interfaceManager.GetWBWorkflowInfo(_workflowID);
         _actionInfo = _workflowInfo.WorkflowActions[_actionName];
         _actionParameter = _actionInfo.Parameters["SomeParameter"];
         if(_actionParameter != null)
         {
             tbxSomeParameter.Text = _actionParameter.Properties["DefaultValue"].ToString();
         }
 
         #endregion
         #region Button
 
         btnLaunchAction.Click += btnLaunchAction_Click;
 
         #endregion
 
     }
 
     void btnLaunchAction_Click(object sender, EventArgs e)
     {
         _actionParameter.Value = tbxSomeParameter.Text;
         Datapolis.WorkBox.Utilities.WBInterface.WBResultInfo resultInfo = _interfaceManager.LaunchWBAction(_workflowID, _actionInfo);
         if(resultInfo.Result == true)
         {
             if (string.IsNullOrEmpty(_redirectUrl))
                 this.Page.Response.Redirect(_workflowInfo.ListDefaultViewUrl);
             else
                 this.Page.Response.Redirect(_redirectUrl);
         }
         else
         {
             throw new Exception("Action was not launched. Error: " + resultInfo.Message);
         }
     }
 }
 

Deploy


To deploy solution – so your form will be available on SharePoint – just right click on solution and choose deploy.


Next Steps


Optionally, after reading this walkthrough you can see the same custom form code attached in SDK Samples in Download section.