Introduction to Visio Services in SharePoint 2010

In this blog post article, I will show you guys how to develop a basic SharePoint workflow using Visio. As part of SharePoint 2010, Microsoft introduced a new feature called Visio Services. This Service Application component allows you to visualize and publish business process diagrams into the SharePoint Context. Quite frankly, this is probably the feature that got me the most excited when I first saw all that SharePoint 2010 had to offer over its MOSS predecessor. 

Developing workflows using Visio is something that everybody is familiar with. Microsoft has really put a lot of emphasis on simplifying the users’ experience with their 2010 release of SharePoint. There have already been several integration points between some of the office suite that I call the “Core Office Clients”, such as Word, PowerPoint, and Excel with the 2007 version of the product. This time around, Microsoft built on the integration of the “Extended Office Clients”, such as Access, Project, OneNote, Visio, and the newly born SharePoint Workspace.

Enough talking, let’s get to the meat of this article. In order for you to start developing your SharePoint Workflows in Visio, you will need the following tools installed on your client machine:

  • Microsoft Visio 2010 Premium or Professional
  • SharePoint Designer 2010;
  • SharePoint Server 2010;

Note that the Visio Services component only comes with the SharePoint Server version; the SharePoint Foundation package doesn’t include these components. Also note that only the premium and pro versions of Visio will allow you to publish diagrams over to your SharePoint Server. SharePoint Designer is also a must to accomplish the task at hand. Visio allows one to map processes into a diagram, but SharePoint Designer is required to put the logic into the different Workflow boxes.

Let’s start by opening Visio. Upon opening the program, you will be presented with the Template Selection screen. The template that allows you to create SharePoint workflows is located in the Flowchart category. You need to go ahead and select that category. Simply click the following icon:

Inside that category, you should see the Microsoft SharePoint Workflow as an option, click on it to select it:

Then click on the Create button in the right area. Doing this will automatically launch a new canvas, and you’ll see SharePoint stencils appear in the toolbox.

The two most important stencils that every SharePoint Workflow should have is the Start and Terminate states.

Go ahead and drag each one onto the drawing area. Now, that we have the start and end states specified, we need to add the meat of our workflow. For this example, we will assume we want to map a business process where the user wants a new task asking for approval to be sent to a user’s manager every time a new item is added to a document library. For the demo’s purpose, we will only handle the case where the manager’s approves the document, and won’t even bother adding logic for the case where it would be rejected.

The first thing we want, is to be able to give the user who initiated the workflow some feedback as to where in the queue of the approval process the document sits. What we want to do for this is to set the workflow’s status. This status will be displayed back to the user besides his document entry, so it will be very obvious what step of the approval process the document in in. The next stencil we need to insert is located under the SharePoint Workflow Action sub category. It is the Set workflow status shape. Drag and drop that shape onto the drawing area, and add an incoming connection to it starting from the Start state shape. You can rename the shape to give more insights as to what we expect the workflow to do:

Your workflow should now look like mine above. The next shape to add is the Assign to-do item one, which tells the system to assign a new task to a user. Next, make sure all shapes on the drawing area are connected in a sequential order. The final diagram should look like the following:

Now that our diagram is completed, we want to ensure it is a valid SharePoint Workflow. Visio now includes a workflow validator feature in the Ribbon, under the Process tab. By clicking the Check Diagram button, Visio will automatically check you workflow for problems.

If no errors are detected, the following message will pop-up:

If you see this message, you are good to go. Otherwise, you probably want to re-run through my article to make sure you got all steps right. Assuming you got the successful validation message above, you are now ready to export your diagram. To do this, simply click on the Export button also located under the ribbon’s Process tab.

Clicking this button will ask you to save the SharePoint Workflow locally as a Visio Workflow Interchange (VWI) format. Make sure you save the file somewhere you have access to.

We now need to add some meat to the workflow skeleton, time to bring up your new best friend, SharePoint Designer 2010. From the interface, you want to open the site that contains the list on which you want your workflow to run on. My recommendation is always to browse to your SharePoint web site via the web browser and to select the Edit in SharePoint Designer option from the Site Actions menu, assuming the option was enabled at the farm level from Central Admin, which it should be by default.

For the purpose of this exercise, I’ve created a new Document Library called “Documents for Approval”. This is the list I will be attaching my workflow onto. It only contains the default out-of-the-box Document library columns.

With SharePoint Designer opened, select Workflows from the left menu:

You’ll notice that the ribbon automatically changes selection, and will see several workflow related options appear up there. The one we are interested in is the Import from Visio one. Go ahead and select that option, doing this will ask you to select a VWI file.

Browse to the file you’ve created from Visio, and click Next. On the following screen, you are asked to give your workflow a name, and to select what list to associate it with. Name the Workflow “Introduction to Visio Services”, and select whatever list you want your workflow to be associated with. In my case, I went and selected my Documents for Approval list I had previously created. After you’ve entered the required information, click on Finish.

After clicking the button, you are automatically brought to the Edit Workflow screen. In the main area of SharePoint Designer, you should now see that various actions you’ve specified in your Visio Diagram.

By default, the workflow is configured to set the Workflow’s status to Canceled. If you remember correctly, in our diagram we mentioned that we were going to set the workflow’s status to Task Assigned. To do this, simply click on the underlined Canceled link, and type in the appropriate status. Moving on to the second option, we need to specify details about the task we want assigned to the user’s manager. Clicking on the a to-do-item link will automatically launch the Custom Task Wizard Screen:

From that screen, click Next. On the second screen, we need to enter a name and a description for the task to be assigned. In the Title field, enter Review & Approve Document, and in the Description box enter You need to review the user document, and complete this task to approve the document. Once the information has been properly entered, click on Finish.

We now need to tell the workflow who to assign the task to. Click on the these users link to open the Select Users dialog box. In there, you’ll notice the option People/Groups from SharePoint site…, click on it. In the next dialog box, simply type in the name of the manager’s responsible for approving the documents. In my case, I will select myself as the manager. Once the user is selected from the list, click on Add>> and then on OK.

Back on the previous screen, simply click on OK.

Your workflow actions should now look like the following:

The next step is to set the workflows setting to let SharePoint know when to start it. Switch to the Workflow Settings screen by clicking the Workflow Settings button from the ribbon.

We want to tell the workflow to start automatically as soon as a new item is added or whenever an existing one is modified. From Start Options area, uncheck the Allow this workflow to be manually started checkbox, and check both the Start workflow automatically when an item is created and the Start workflow automatically when an item is changed.

Now here comes the part where you guys will witness the real power of the Visio Services. We want to tell SharePoint to let us visualize the current state of a workflow at any time during the process execution. To do this, we need to check the Show workflow visualization on status page checkbox from the Settings section.

If this option is grey Shaded, you need to go back to your SharePoint site and ensure you have enabled the SharePoint Server Site Collection Enterprise features. Once that is done, simply close and re-open SharePoint Designer’s.

Let’s publish this workflow back onto our SharePoint workspace. To do this, all you have to do is click on the Publish button from the Ribbon, and wait for it to be deployed.

Back to our SharePoint site, navigate to the document library onto which the workflow has been attached, and add a new document to it. After a couple of seconds, and after hitting refresh once or twice, you’ll notice a new column that appeared in the default view. This column shows you the current workflow’s state, which in our case is the default “Task Assigned” value we gave it.

Clicking on the workflow state, will bring you to the workflow status page. Be aware that by clicking this link, you may experience a wide variety of emotions when you’ll see what’s on the other side. Some may start laughing inadvertently, others may start to crying, so other may simply feel like rubbing the furry wall. Guess what’s on that page? Yes you’ve guess right, SharePoint lets you visualize your original Visio diagram, and lets you see exactly where in the approval process we are at. In our case, we are stuck at the Assign a to-do item step, because the workflow is waiting for the manager’s to approve the document before completing.

If you scroll down the page a bit, you’ll see the actual task that was assign to the approval manager.

In order for you to complete the current workflow, simply sign-in as that person and complete the task. To complete the task, simply select “Edit Item” from the dropdown menu beside the Task’s Title, and click on Complete Task on the next screen:

Completing the task will cause the current page to refresh, and you will now be able to see that all steps in our current workflow have completed successfully.

Voilà, that completes our Introduction to Visio Services. Please note that we could have simply opened SharePoint Designer right from the start, and have created our workflow in there. Publishing it over to SharePoint using the same settings specified above would have still generated the Visio diagram on the Workflow Status page, and have allowed you to visualize the status of your current workflow process. Visio simply makes it easier for one to organize his thoughts, and to clearly name shapes to avoid any confusion.

Tips for Troubleshooting SharePoint Performance Issues

As part of my routine, I try to answer about a dozen SharePoint forums questions on MSDN every week. Lately, most of the questions I’ve been answering were about troubleshooting performance in SharePoint sites, so I’ve decided to go ahead and write a blog post about the various methods and tools available to SharePoint Admins to identify performance issues. 

First off, if it is a specific page that seems to be causing slow downs, you probably want to verify that the page doesn’t have any “Closed WebParts”. A closed web part is a web part that is still being processed by the .NET framework, but that never actually gets displayed on the page. In order to view all web parts on a page, you’ll need to switch to the web part page maintenance administrative page. This can be achieved by appending the following querystring parameter in the page’s url:

contents=1

ex:

http://server/default.aspx?contents=1

On this page, you’ll see a list of all web parts that have to be processed for the page to load. The column we are interested in is the “Open on Page?”” column, which indicates whether or not the web part is closed on the page. The following screenshot shows you an example of a page that has two Web Analytics web parts that are closed. Note that none of these two web parts are actually displayed to the user when loading the page.

Now, in order for the page to stop processing them, we will have to select them both, using the checkbox beside the web part’s’ titles, and then click on the Delete menu at the top. Take good note of the Caution message at the bottom of the page, doing this will actually edit the Shared version of the page, that’s the version accessible to everybody. If you want to only edit the personal view you’ve created for the page, you will have to click on the “Switch to personal view” menu. All of this can also be achieved using SharePoint designer, but details on how to do it with this tool are not covered in this article.

The second option you have to troubleshoot a specific page’s performance, is the Developer’s Dashboard. This is a new feature Microsoft introduced in SharePoint 2010, and requires some configuration settings to be set in order to use it. The developer’s dashboard is a neat little utility that allows administrator to view details about a specific page’s processing, and drill down into each components of it to help identify bottlenecks.

The display property of the dashboard can take 3 values: on, off, or ondemand. On demand will provide the user with a dashboard icon beside personal menu a the top right of the page, allowing them to show and hide the information panel. The on-demand mode is probably the one you’ll want to use. Below is a short PowerShell script I have developed to allow administrators to activate the Developer’s dashboard. This script should be run inside the SharePoint 2010 Administration Shell.

$spwebapp = Get-SPWebApplication http://localhost
$devDashboardSettings = $spwebapp.WebService.DeveloperDashboardSettings
$devDashboardSettings.DisplayLevel = “ondemand”;
$devDashboardSettings.TraceEnabled = $true;
$devDashboardSettings.Update();

The following picture shows the developer’s icon once the settings has been set to ondemand:

devdashboardicon

Clicking on this icon will automatically open and information pane at the bottom of the screen. This panel contains information about loading time for each of the various components of the page. In the example below, we see that the two “closed Analytics Web Parts (the same as the example above). are taking a combined total of 0.19 ms to load.

devdashinfo

You can also get other very useful information from this panel such as how long it takes the Search Scopes drop down to be populated, the wiki conversion time, and so on. You can also view details about Critical errors and warning issued by the Health Analyzer service from within this panel. The example above shows that three configuration warning were reported. Clicking on the associated warning id will automatically launch a second windows describing what the error/warning is all about, and how to go about it. Now, assuming you are not happy with the information provided, and need to go even more granular, Microsoft is allowing you to open the stack trace and see exactly what has been executed on the page. This was enabled by the $devDashboardSettings.TraceEnabled = $true; line in my script above. Setting the trace value to true, adds a link at the bottom of the information panel named “Show or hide additional tracing information…”. Clicking this link will load an extensive list of all the various .NET, database, and IIS calls that were made by the page. This comes in very handy when trying to debug custom code, since it allows a developer to see exactly how long each method took to execute. The following screenshot shows an example of trace entries reported by the developer’s dashboard:

devdashtracing

To wrap it up, SharePoint provides you with several ways to troubleshoot performance issues, you just need to take the time to analyze all the information that is provided to you.