How To: Enable Collaboration on Tasks in SharePoint

Learn how to create a task collaboration workspace in Duet Enterprise for Microsoft SharePoint and SAP.

Applies to: Duet Enterprise for Microsoft SharePoint and SAP Server 2.0 | Office 2010 | SharePoint Server 2010

In this article
Steps to Create a Task Collaboration Workspace
Creating an Empty SharePoint Project
Creating the Task Details Web Part
Creating the User Management Web Part
Deploying the Web Parts
Adding the Web Parts to the Site Collection Gallery
Saving the Site as a Template
Updating the BDC Model with the Template ID
Importing the BDC Model

You can use a task collaboration workspace to list and track task details and assign users to tasks. This topic shows you how to create a task collaboration workspace. The workspace consists of a Task Details Web Part that displays the details of a task, and a User Management Web Part that enables you to add or remove users assigned to a particular task.

You can add these Web Parts to the Microsoft SharePoint Server Site Collection gallery and save the Web Parts with a template. If the BDC model is updated with the template ID, the collaboration sites are created by using the new template.

When you have completed the procedures in this topic, you will have created a site that resembles the site depicted in Figure 1.

Figure 1. Task collaboration workspace

Sample task collaboration workspace

Note

To create a Duet Enterprise collaboration workspace in a different site collection, you must modify the collab-on action URL in the BDC model to point to the target site collection URL.

The administrator must also ensure that the following features are activated on the target site collection:

  • Entity collaboration feature

  • OBAReportDataTypes feature

Steps to Create a Task Collaboration Workspace

To create the task collaboration workspace, you perform the following steps:

  1. Create a new SharePoint project.

  2. Create the Task Details Web Part.

  3. Create the User Management Web Part.

  4. Deploy the Web Parts.

  5. Add the Web Parts to the Site Collection gallery.

  6. Save the site as a template.

  7. Update the BDC model with the template ID.

The following procedures describe these steps in detail.

Creating an Empty SharePoint Project

The steps in the following procedure describe how to create an empty SharePoint project in Visual Studio 2010.

To create an empty SharePoint project

  1. Start Visual Studio 2010 by using the Run as Administrator option.

  2. On the File menu, click New, and then select Project.

  3. In the New Project dialog box, expand the Visual C# node, expand the SharePoint node, and then select the 2010 node.

  4. In the Templates pane, select Empty SharePoint Project, name the solution, and then click OK. The SharePoint Customization Wizard opens, which enables you to select the site that you want to use to debug the project and the trust level of the solution.

  5. In the SharePoint Customization Wizard, click Deploy as farm solution, and then click Finish to accept the default local SharePoint site.

    Note

    Any Web Part must be a farm (fully trusted) solution.

Creating the Task Details Web Part

This procedure describes how to create the task details Web Part.

To create the Task Details Web Part

  1. In Solution Explorer, right-click the solution, point to Add, and then click New Item.

  2. In the Add New Item dialog box, expand the SharePoint node, and then expand the 2010 node.

  3. In the 2010 node, click Visual Web Part, name the item TaskDetails, and then click Add. The Web Part appears in Solution Explorer. This action generates the library references and, in our example, TaskDetailsWebPart.cs.

  4. Add the following code to TaskDetailsWebPart.cs.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.WebPartPages;
    using System.Web;
    using System.Web.UI.WebControls;
    using Microsoft.SharePoint;
    using OBA.Server.Taskflow.UI;
    using System.Collections.Specialized;
    
    namespace SimpleWebpart
    {
        public class SimpleWebPart : Microsoft.SharePoint.WebPartPages.WebPart
        {
            private string displayText = "Hello World!";
            [System.Web.UI.WebControls.WebParts.WebBrowsable(true), System.Web.UI.WebControls.WebParts.Personalizable(true)]
            public string DisplayText
            {
                get { return displayText; }
                set { displayText = value; }
            }
            protected override void Render(System.Web.UI.HtmlTextWriter writer)
            {
                try
                {
                    SPWeb web = SPContext.Current.Web;
                    TaskflowProperties collabinstance = new TaskflowProperties(SPContext.Current.Web);
                    this.Title = "Task Properties";
                    writer.Write("Title: " + collabinstance.TaskTitle);
                    writer.WriteBreak();
                    writer.Write("Status: " + collabinstance.TaskStatus);
                    writer.WriteBreak();
                    writer.Write("Reason: " + collabinstance.TaskReason);
                    writer.WriteBreak();
                    if (collabinstance.TaskOutcome.Equals(string.Empty))
                        writer.Write("Task OutCome: " + "No Decision Taken Yet");
                    else
                        writer.Write("Task OutCome: " + collabinstance.TaskOutcome);
                    writer.WriteBreak();
    
                    StringCollection attachemnts = collabinstance.TaskAttachmentUrl;
                    if (attachemnts.Count == 0)
                        writer.Write("No Attachments for this task");
                    else
                    {
                        writer.Write("Attachments:");
                        foreach (string s in attachemnts)
                        {
                            writer.WriteBreak();
    
                            writer.Write("<a href =" + 
                            new Uri(s).AbsoluteUri + ">" + 
                            s.Split('/').GetValue(s.Split('/').Length-1).ToString() + 
                            "</a>");
    
                        }
                    }
                    writer.WriteBreak();
                    writer.Write("BizDocXML: "+collabinstance.BizDocXml);
                    writer.Write("Test"+ web.AllProperties["test"]);
                }
                catch (Exception e)
                {
                    writer.Write(e.StackTrace);
                }
            }
        }
    }
    

Creating the User Management Web Part

The User Management Web Part, which uses the CollabOnUserManager class, enables administrators to add or remove users and list task partners. This procedure describes how to create the User Management Web Part.

To create the User Management Web Part

  1. In Solution Explorer, right-click the solution, point to Add, and then click New Item.

  2. In the Add New Item dialog box, expand the SharePoint node, and then expand the 2010 node.

  3. In the 2010 node, select Visual Web Part, name the item UserManagement, and then click Add. The Web Part appears in Solution Explorer. This action generates the library references and, in our example, UserManagementWebPart.cs.

  4. Add the following code to UserManagementWebPart.cs.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    using System.Security;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.SharePoint.Utilities;
    using Microsoft.SharePoint.Workflow;
    using System.Collections;
    using OBA.Server.Taskflow.UI;
    
    [assembly:AllowPartiallyTrustedCallers]
    namespace AddRemoveUser
    {
        public class UserManagement : Microsoft.SharePoint.WebPartPages.WebPart
        {
            private PeopleEditor m_PplEditor;
            private Button m_AddButton;
            private Button m_RemoveButton;
            private TextBox m_textbox;
            // CreateChildControls
            protected override void CreateChildControls()
            {
                base.CreateChildControls();
                m_PplEditor = new PeopleEditor();
                m_AddButton = new Button();
                m_AddButton.Click += new EventHandler(m_AddButton_Click);
                m_AddButton.Text = "Add User";
                m_RemoveButton = new Button();
                m_RemoveButton.Click += new EventHandler(m_RemoveButton_Click);
                m_RemoveButton.Text = "Remove User";
                m_textbox = new TextBox();
                this.Controls.Add(m_textbox);
                this.Controls.Add(m_PplEditor);
                this.Controls.Add(m_AddButton);
                this.Controls.Add(m_RemoveButton);
                CollabOnUserManager collabUser = new CollabOnUserManager();
                TaskUser[] taskuser = collabUser.GetTaskUsers();
                foreach (TaskUser tu in taskuser)
                {
                    m_textbox.Text = m_textbox.Text + "User: " + 
                    tu.User.LoginName + " : Category: " + 
                    tu.TaskUserCategory.ToString() + "<br/>";
                }
            }
    
            void m_RemoveButton_Click(object sender, EventArgs e)
            {
                PickerEntity entity = (PickerEntity)m_PplEditor.ResolvedEntities[0];
                Hashtable data = entity.EntityData;
                string loginName = entity.Key;
                string email = data["Email"].ToString();
                string name = entity.DisplayText;
                CollabOnUserManager collabUser = new CollabOnUserManager();
                collabUser.AddRemoveUser(loginName, email, name, CollabOnUserAction.RemoveUser);
            }
    
            void m_AddButton_Click(object sender, EventArgs e)
            {
                PickerEntity entity = (PickerEntity)m_PplEditor.ResolvedEntities[0];
                Hashtable data = entity.EntityData;
                string loginName = entity.Key;
                string email = data["Email"].ToString();
                string name = entity.DisplayText;
                CollabOnUserManager collabUser = new CollabOnUserManager();
                collabUser.AddRemoveUser(loginName, email, name, CollabOnUserAction.AddUser);
            }
        }
    }
    

Deploying the Web Parts

The steps in the following procedure describe how to deploy the Web Parts.

To deploy the Web Parts

  1. In Visual Studio, right-click the project, and then click Deploy.

    Deployment occurs, and the SharePoint site opens. The Web Part is added to the SharePoint 2010 Web Part gallery automatically.

  2. Open and edit any Web Parts page, and then add the Web Part.

  3. Click Insert, and then click Web Part. Select the Web Part from the Custom category. The Web Part is displayed on the page.

    Note

    When you close Internet Explorer or press SHIFT+F5 in Visual Studio, Visual Studio retracts the Web Part (if Auto-retract after debugging is selected on the SharePoint tab of the ListProjects property page) and resets Internet Information Services (IIS). If you click Deploy Solution on the Build menu, Visual Studio deploys the solution on the development computer so that you can use the Web Part independently from Visual Studio.

For more information about working with Web Parts, see How to: Work with Web Parts on a Page (https://msdn.microsoft.com/en-us/library/ee539301.aspx).

The steps in the following procedure describe how to add the Web Parts to the site collection gallery.

  1. On the site home page, click Site Actions, and then click Site Settings.

  2. On the Site Settings page, under Galleries, click Web parts.

  3. On the All Web Parts page, click Doc, and then click New Document.

  4. Select the Web Parts to add to the gallery, and then click Populate Gallery.

  5. Open the page where you want to add the Web Part, click Site Actions, and then click Edit Page.

  6. On the Editing Tools menu, click Insert, and then click Web Part.

    The list of currently installed Web Parts appears.

  7. In the Categories list, click the Miscellaneous node.

  8. Select the Web Part to add to the page, and then click Add.

Saving the Site as a Template

The steps in the following procedure describe how to save the site as a template.

To save the site as a template

  1. On the Site home page, click Site Actions, and then click Site Settings.

  2. On the Site Settings page, under Site Actions, click Save site as template.

  3. On the Save as Template page, type the File Name, Name, and Description, select the check box to indicate whether to include content, and then click OK.

    Note

    Some customizations, such as custom workflows, are present in the template only if you choose to include content. Be aware that including content can increase the size of your template.

    The new template is displayed in the Site Settings Solutions gallery.

    The BDC model file provided with Duet Enterprise can be used as a starting point for all the approval task types.

    Provide each task type with a unique entity name because the collaboration site template will differ for each task type.

    Note

    To use the BDC service application to perform this task, you must be a farm administrator or administrator of the service application.

Updating the BDC Model with the Template ID

The steps in the following procedure describe how to update the BDC model with the template ID.

To update the BDC model with the template ID

  1. Open the Duet EnterpriseBDC model file.

    In the model file, you must define the site template for the site you are creating for the task workflow collaboration. The WorkSpaceSiteTemplate property defines the template ID to use.

  2. Modify the WorkspaceSiteTemplate property.

    Use the following example to change the WorkSpaceSiteTemplate property. Edit the instance of this property that appears inside the entity with the Workflow Name attribute and the SAP.Office.DuetEnterprise.Workflow.AccountNamespace attribute.

    Entity Namespace="SAP.Office.DuetEnterprise.Workflow.Account" 
    Version="1.0.0.2" EstimatedInstanceCount="10000" 
    Name="Workflow" DefaultDisplayName="Workflow">
        <Properties>
           <Property Name="WorkspaceSiteTemplate" Type="System.String">TaskflowtemplateId</Property>
           <Property Name="Title" Type="System.String">Title</Property>
           <Property Name="ExcludeFromOfflineClientForList" 
           Type="System.Boolean">True</Property>
        </Properties>
    

    Note

    Property is a mandatory property under the Properties node.

  3. After making the changes, manually import the BDC model file.

    Note

    To import the model file, you must be a farm administrator or administrator of the service application.

    For detailed steps that describe how to import BDC models, see Manage BDC models (SharePoint Server 2010) (https://technet.microsoft.com/en-us/library/ee524073.aspx).

Importing the BDC Model

The steps in the following procedure describe how to import the BDC model.

To import a BDC model

  1. On the Central Administration site, in the Application Management section, click Manage service applications.

  2. In the list of service applications, click the row that contains the Business Data Connectivity (BDC) service application.

  3. On the Service Applications tab, in the Operations section, click Manage.

  4. On the Edit tab, in the BDC models group, click Import.

  5. On the Import BDC model page, in the BDC Model File field, click Browse to find the BDC model or resource file.

  6. In the File Type field, select the model as the type of BDC model file to import.

For information about how to create, package, and deploy Web Parts, see the following:

See Also

Other Resources

Business Connectivity Services in SharePoint Server 2010

Manage BDC models (SharePoint Server 2010) (https://technet.microsoft.com/en-us/library/ee524073.aspx#importamodel)

Microsoft Duet Enterprise for SharePoint and SAP API (https://connect.microsoft.com/site1051/Downloads/DownloadDetails.aspx?DownloadID=29591)

Configure and deploy Web Parts (https://technet.microsoft.com/en-us/library/cc261736.aspx)