Friday, December 30, 2011

How to create workflow in Visio and import it in Sharepoint Designer 2010 - Part 2

In previous blog we saw how to create and export the workflow diagram in Visio 2010 ( How to create workflow in Visio and import it in Sharepoint Designer 2010 - Part 1 ). In this blog we import workflow file in SharePoint Designer 2010.

  1. Open SharePoint Designer 2010 -> Click on "Open Site" -> In open site window enter site URL on which you want to import the workflow.
  2. Click on "Workflows" in Navigation -> Click on "Import from Visio" button from top ribbon -> In Import workflow from Visio Drawing browse the path of export file and click on Next button.
  3. In this screen Click on List Workflow and from drop down select "Reimbursement Request" list and click on finish.
  4. After click on finish you got following workflow view now we have to set the condition and values for this imported workflow.

    1. Click on "Value" in top if statement , here we have to select expense and specifies the limit after which approval is required for it. set the value as shown in fig. below


    2. Set approval attributes as shown in fig. below


    3. Click on value link after "Is Approved?"  from pop up window set approval status field from field from source drop down and set condition equals to approved. If approval status is equal to approved then you have to inform user that his request has been approved by department head. for that set following values as shown in fig. below. and for update item , select current item, add Authorized field and set its values to Yes.

    4. Repeat above step for remaining else parts with appropriate messages.
  5. Save current workflow and click on "Check for Errors" button which is on top of ribbon. if workflow complied successfully then pop up message shows "The workflow contains no errors". Go to start options of workflow and check on "Start workflow automatically when item is created." and click on button publish button to publish workflow in selected list.
  6.  
After this step we had workflow which is published on site, now go to site and add item with Expense amount greater than Rs. 200.

Wednesday, December 28, 2011

Content type hub problem with Blank Site Template

As I mentioned in how to deploy content type hub in my previous blog ("Content Type Hubs Publishing in Sharepoint 2010"), after following blog content type is not appearing on site may required to activate the Taxonomy feature on that site, following command required to activate the feature

STSADM -o activatefeature -id 73EF14B1-13A9-416b-A9B5-ECECA2B0604C -url http:// -force

Power Shell Command
Enable-SPFeature -id 73EF14B1-13A9-416b-A9B5-ECECA2B0604C -URL

Hope this work for you also....


Good luck :-)

Wednesday, December 21, 2011

How to setup content type publishing hub in SharePoint 2010

What is Content Type Hub ?
Content type hub is new feature of SharePoint 2010 to manage content type centrally (Content Type Gallery) and publish them to subscribed sites.

Prerequisite :
  1. Create two web application on two separate port number. we called site A as publisher and site b as subscribed site.
  2. Create content type on site A called "Content Type Hub Demo" of document base type. 

Create service to deploy content type hub
 

  1. Open SharePoint 2010 Central Administration - > Click on Manage service applications under Application Management section -> Click on New and select Managed Metadata Service


  2. On "Create New Managed Metadata Service" window change following values
    Name : Content Type Hub
    Database Name : Content_Type_Hub_Database
    Use existing application pool: SharePoint Web Service Default
    : "Enter the url of web site which going to act as publisher for content type". Click on "Ok" button

How to deploy content type hub ?To deploy content type hub on site you required to activate "Content Type Syndication Hub" feature on publisher site which in Site Collection features.


After activating feature go to content type gallery of site, click on Site Actions -> Site Settings -> under Galleries section you find "Site Content Types" click on it. On site content types page select "Content Type Hub Demo" content type.

In Settings section of Content type Click on "Manage publishing for this content type" and On Content type publishing select "Publish" and click on "OK" button.
After this we required to run Timer jobs manually first time to publish the content type. Go to "SharePoint 2010 Central Administration" -> Click on Monitoring -> Click on Review job definitions.

In Job Definitions run the jobs in following order
1.Content type hub
2.Content Type Subscriber job for publishing site
3.Content Type Subscriber job for subscriber sites.

Go to subscriber site and Content type gallery you find the "Content Type Hub Demo" content type.






Monday, December 19, 2011

How to create workflow in Visio and import it in Sharepoint Designer 2010 - Part 1

This blog shows how easy to create a workflow in  Microsoft Visio 2010 and import it in Sharepoint Designer 2010. This part contains the prerequisites required and how to design workflow in Microsoft Visio 2010. In this blog we create work for "Reimbursement of Expenses", if my expense amount is less then specified limit then request is directly approved otherwise it goes to Department Head for approval.

Prerequisites :
I create custom list called "Reimbursement Request" and added following field into it.
  • "Description" type of Multiple lines of text.
  • "Expense Amount" type of Currency.
  • "Authorized" type of  "Yes/No".
  • "Department Head" type of "person and Group".
Design workflow with Microsoft Visio :

1. Open Microsoft Visio 2010 : Click on Start -> All Programs -> Microsoft Office -> Click on "Microsoft Visio 2010".

2. Create "Microsoft Sharepoint Workflow" : In Template Categories section click on Flowchart -> "Microsoft SharePoint Workflow" and click on Create button as shown in fig. below


3. Create workflow diagram

  1. Each workflow diagram has its start and terminate condition so we put this two condition on drawing area. shown in fig.


  2. Under "Shapes" panel click on "SharePoint Workflow Conditions", drag and drop "Compare data source" control on drawing area. double click on control and change it display text. Click on "SharePoint Workflow Actions"  and drag and drop "Start approval process" and "Send an email" as shown in fig. below


  3. Now we have to add condition for Compare data source control, right click on arrow of "Is Expense Amount Required Authorization?"  select "Yes" from popup now. click on other arrow and set "No" condition for it. repeat same for "Is Approved?" control.

  4. After setting all condition as shown in fig above click on Process tab from top ribbon and click on "Check Diagram" button. This will validate your workflow diagram and shows if any error before exporting this workflow diagram we have to clear all errors. Once its shows "No issue found" message click on export button and save this drawing as "Visio Workflow InterChange" type. After this step you had workflow ready to use in sharepoint designer 2010.
  5. How to use exported file in "SharePoint Designer 2010" explained in next part to this blog.





    Thursday, December 15, 2011

    Connect Chart Web Part to SQL database in Sharepoint 2010


    1. This blog shows you how to provide data for OOB Charting Web part in Sharepoint 2010. First insert the chart web part into you page as shown in fig. below


























    2. Create custom web part and specify the database connection as I am retrieving chart data from sql server 2008 database. Copy paste following code into webpart and deploy web part to site collection

    [ToolboxItemAttribute(false)]
        [Serializable]
        [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
        [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
        public class ChartDataProviderWebPart : WebPart, IWebPartTable
        {

            SqlDataAdapter sda;
            Timer _timer;
            DataTable _table;
            Label _lblMessage;
            string databaseConnectionString = "Data Source=.;Initial Catalog=Demo_Database;user id=username;password=yourpassword;"; // Change setting

            protected override void CreateChildControls()
            {
    // Timer control added to refresh chart after every 30 second
                _timer = new Timer();
                this._timer.Interval = 30000;
                this._timer.Tick += new EventHandler<EventArgs>(_timer_Tick);
                this._timer.Enabled = true;
                this.Controls.Add(this._timer);
                this.Controls.Add(this._lblMessage);
            }

            void _timer_Tick(object sender, EventArgs e)
            {
                this._lblMessage.Text = string.Format("Last updated @ {0} ", DateTime.Now.ToString());
            }
           
            public ChartDataProviderWebPart()
            {
                try
                {
                    _table = new DataTable();
                    this._lblMessage = new Label();
                    this.sda = new SqlDataAdapter("select * from tblData order by name", new SqlConnection(this.databaseConnectionString));
                    this.sda.Fill(this._table);
                }
                catch (Exception ex)
                {
                    this._table.Columns.Add(new DataColumn("Name"));
                    this._table.Columns.Add(new DataColumn("Value"));
                }          
            }
          
            public void GetTableData(TableCallback callback)
            {

                callback(_table.Rows);
            }

            public PropertyDescriptorCollection Schema
            {
                get
                {
                    return TypeDescriptor.GetProperties(this._table.DefaultView[0]);
                }
            }

            public bool ConnectionPointEnabled
            {
                get
                {

                    object o = ViewState["ConnectionPointEnabled"];
                    return (o != null) ? (bool)o : true;
                }
                set
                {
                    ViewState["ConnectionPointEnabled"] = value;
                }
            }

            [ConnectionProvider("Table", typeof(DataTableProviderConnectionPoint), AllowsMultipleConnections = true)]
            public IWebPartTable GetConnectionInterface()
            {
                return new ChartDataProviderWebPart();
            }


        }
        public class DataTableProviderConnectionPoint : ProviderConnectionPoint
        {
            public DataTableProviderConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType, string name, string id, bool allowsMultipleConnections)
                : base(callbackMethod, interfaceType, controlType, name, id, allowsMultipleConnections)
            {

            }

            public override bool GetEnabled(Control control)
            {
                return ((ChartDataProviderWebPart)control).ConnectionPointEnabled;
            }

        }

    3. Go to page where you inserted chart web part, insert above deployed webpart on same page. Click on Data & Appearance from chart web part -> Click on Connect Chart To Data


    4. After clicking on Connect Chart To Data you got Step by Step Data Connection Wizard
    • Step 1: Choose Connect to another web part option for this step and click on Next button 

    • Step 2: Connect to another Web Part in drop down you found the name of web part that you deployed now



    • Step 3:  On retrieve data step select  Table as source data format in data format dropdown and click on next button

    • Step 4: On Bind Chart to Data , set Y Field to "Value" and X Field to "Name" as shown in fig. below and click on Finish 



    • This web part refresh after evey 30 second for retriving data from database.







    Friday, December 2, 2011

    How to programmatically associate a workflow to a list in Sharepoint

    In one of your project we have to attach "Sharepoint approval workflow" to list when feature is activated on the web.

    Prerequisite
    :
    • SharePoint 2007 Workflows activated on site collection level
    • Task list of content type Task, for storing task created to users.
      private void SetWorkFlow(SPWeb web, string listName)
            {
    web.AllowUnsafeUpdates = true;

    string workflowAssocName = string.Format("{0} - Sharepoint Approval", listName);
    SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates.GetTemplateByName("Approval - SharePoint 2010",
    System.Globalization.CultureInfo.CurrentCulture);
    SPList myList = web.Lists[listName];


    // Try to get workflow history and task list
    SPList historyList = web.Lists["Workflow History"];
    SPList taskList = web.Lists["Tasks"];


    // Create workflow association
    SPWorkflowAssociation workflowAssociation = SPWorkflowAssociation.CreateListAssociation(
    workflowTemplate, workflowAssocName, taskList, historyList);

    // Set workflow parameters
    workflowAssociation.AllowManual = false;
    workflowAssociation.AutoStartCreate = true;
    workflowAssociation.AutoStartChange = false;
    workflowAssociation.ContentTypePushDown = false;

    // The AssociationData property represents for the settings that user see in 2nd screen when creating workflow in SharePoint UI
    var associationDataXml = XElement.Parse(workflowAssociation.AssociationData);

    // Update modifed xml segment back to WorkflowAssociation object
    workflowAssociation.AssociationData = Add_Association_Data(web.ParentWeb, associationDataXml);

    // Add workflow association to my list
    myList.WorkflowAssociations.Add(workflowAssociation);

    // Enable workflow
    workflowAssociation.Enabled = true;
    myList.Update();

    web.Update();
    web.AllowUnsafeUpdates = false;
    }

       private String Add_Association_Data(SPWeb oWeb, XElement associationDataXml)
            {
                String sDate = String.Empty;
                XNamespace dNamespace = @"http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields";
                XNamespace pcNamespace = @"http://schemas.microsoft.com/office/infopath/2007/PartnerControls";
                XNamespace dfsNamespace = @"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution";
                XNamespace MyNamespace = @"http://schemas.microsoft.com/office/infopath/2003/myXSD";
                XNamespace XsiNamespace = @"http://www.w3.org/2001/XMLSchema-instance";

                XElement propertiesWrapper = associationDataXml.Element(dfsNamespace + "dataFields").Element(dNamespace + "SharePointListItem_RW");
                propertiesWrapper.SetElementValue(dNamespace + WORKFLOW_SETTINGS_CANCELONREJECTION, true);
                propertiesWrapper.SetElementValue(dNamespace + WORKFLOW_SETTINGS_CANCELONCHANGE, true);
                propertiesWrapper.SetElementValue(dNamespace + WORKFLOW_SETTINGS_APPROVEWHENCOMPLETE, true);
                propertiesWrapper.SetElementValue(dNamespace + WORKFLOW_SETTINGS_ENABLECONTENTAPPROVAL, true);
                propertiesWrapper.SetElementValue(dNamespace + WORKFLOW_SETTINGS_EXPANDGROUPS, false);

                // Reviewers is Approvers in UI
                XElement xAssignement
                    = associationDataXml.Element(dfsNamespace + "dataFields").Element(dNamespace + "SharePointListItem_RW").
                    Element(dNamespace + "Approvers").Element(dNamespace + "Assignment");

                string ApprovalGroup = "Managers";
                xAssignement.Element(dNamespace + "Assignee").Add(
                    new XElement(pcNamespace + "Person",
                          new XElement(pcNamespace + "DisplayName", ApprovalGroup),
                          new XElement(pcNamespace + "AccountId", ApprovalGroup),
                          new XElement(pcNamespace + "AccountType", "SharePointGroup")
                    )
                );

                return associationDataXml.ToString();
            }




    Hope this will work for you also.............