Posts Tagged ‘workflow’

Simplified SharePoint solution deployment

Wednesday, June 16th, 2010

Any SharePoint developer will have to work with SharePoint Features at some point. Features are a great way to extend the core functionality of MOSS – in Web 2.0 speak, think of them as “plugins” and you’ll understand why they’re useful. Features can take a variety of forms – workflows being one of them. I’ve discussed in the past the usefulness of SharePoint Designer for workflow creation and eventually you’ll need to move to Visual Studio. Features (and workflows) can be designed directly in Visual Studio – support was added in 2005, but its support is further extended in 2008 – Visual Studio will generate all the required bits you need to actually get the workflow ready to be deployed to your SharePoint environment and gives you the all important debugging and code step through stuff. There’s a nice guide to the basics of workflow and Visual Studio.

In fact, there are lots of good tutorials out there on how to get going with workflow and Visual Studio but they’re all rather restricted by the same issue – how to actually deploy the Feature to SharePoint when it’s ready. There’s a rather convoluted series of stsadm commands which essentially equates to

  1. Add solution
  2. Deploy solution
  3. Install feature
  4. Activate feature

And that doesn’t cover what you need to do if you then produce a new version of your feature – redeploying solutions and deactivating features every time gets very tiresome, very quickly! Fortunately, some folks at CodePlex, have, once again, made our lives easier with the excellent Sharepoint Solution Installer. In their words:

This project is a Windows application for an eased and more user friendly installation and deployment of SharePoint 2007 solution files to a SharePoint server farm. Distribute your SharePoint solution files with this installation program instead of a raw script using STSADM.EXE to install and deploy the solution.

This incredibly handy bit of software takes care of everything required to install the .wsp (solution file) that Visual Studio 2008 handily prepares for you. Furthermore, it neatly handles updates, repairs and removals of solutions. Configuring it is a little on the fiddly side – a lot of the info it asks you to provide* is already specified elsewhere in the manifest or feature files – although it seems inevitable that future versions of the tool will find this information directly. It’s definitely possible, because the Trentacular features for SharePoint does it, but the developers of v2 of the tool have already identified some issues with this approach.

Note: Beware the Setup.exe.config file that is bundled in the v1.2.2 download – it includes a key called “FarmFeatureId”. This should actually be “FeatureId” – with the incorrect key name, your feature is not activated at the end of the process!

Stsadm is all well and good, but it’s not exactly user friendly, I prefer to limit my command line activities to my Ubuntu machines. This tool takes out all the guesswork, in a very neat little package. Sometimes the life of a software developer is just too easy…

* The items you need are

  • SolutionId – in Manifest.xml
  • FeatureId – in feature.xml
  • FeatureScope – in feature.xml

Extend SharePoint Designer’s workflow activities

Wednesday, June 16th, 2010

SharePoint Designer 2007 is a useful tool for performing quick tasks in your SharePoint environment. It’s moreorless Frontpage on steroids, but it’s designed to interact directly with SharePoint installations. I’ve used it almost exclusively to create simple workflows – simple being the operative word. And what’s more, it’s now free! You’ll need the likes of Visual Studio to do anything complex, but for every day use where you don’t want to worry about packaging up solutions and features and getting involved with stsadm, SharePoint Designer definitely has its place.

However, it is rather letdown by some of the activities you can use when designing workflows. However, you’re free to create your own custom activities, and, step-up Codeplex and the SPDActivities project which has already got the ball rolling. This is a superb project that adds some much needed functionality to SharePoint designer’s workflows. The two key features for me were being able to send an email with the attachments of a list item attached to it, and the ability to lookup user info. No longer do you have to address emails to DOMAIN\Username – get their friendly name from your catalog!

Well worth a look at all the features. I installed it on my test environment, and then in to live with no problems at all – and it’s really enhanced SharePoint Designer’s usefulness for getting the quick jobs done.

Workflow error help: failed on start and more

Thursday, July 16th, 2009

One of the major selling points of SharePoint is the power of workflows. Designing very basic sequential workflows in Sharepoint Designer 2007 is a very straightforward task using the workflow designer wizard. But unfortunately straightforward is the key word here, as you are limited by the functionality available to you in SharePoint Designer. Simple tasks (e.g., update an item, send an email, etc.) are doable, but, for example, you can’t do any string manipulation other than building “dynamic strings”. So even creating a suitable subject line to an email can require a complicated collection of variables and such like. SPD workflows are also very much “single use” – i.e., they start, they run, they finish. They can wait and so on, but complicated business logic is pretty difficult to program. At that point, you’ll need to get involved with Visual Studio. That’s not without its difficulties, however, and as someone coming from a Visual Studio software background, creating workflows can be a minefield. Certain expectations you may have with Winforms just go completely out the window.

So here are some observations, hints and tips that I’ve picked up during my time with workflows and Visual Studio. Note that I’m using Visual Studio 2008 on an all in one MOSS2007 box (i.e., my development machine) to write these workflows. VS2008 does all of the debugging and deployment for you – if you’re on VS2005 then the process is a little different, as you have to manually develop the XML files that make up the package (which is beyond the scope of this).

1. Workflows don’t run at all – For security reasons, the workflow engine might not run at all if the web application pool is running as an administrative account. You can change the application pool to a network service in central administration.
2. Workflow failed to start (retrying) – this is a horrible error message. First thing to check is that the correlationtoken is set properly – in theory it should be as VS wouldn’t let you start debugging if it wasn’t. For anyone trying to get their head around what a correlationtoken is, don’t fret too much – it’s just a unique “key” that identifies the workflow. For your WorkflowActivated activity, you could set the token as “WorkflowActivatedToken” and then set the OwnerActivityName to the root class of your workflow. You can use the same correlationtoken for all activities in your workflow EXCEPT to say that logical units of the workflow (e.g., things surrounding the creation/use of tasks etc.) should get a separate token.
2b. Note: If you change the name of your class i.e., from Workflow1 to MyAwesomeWorkflow, Visual Studio unhelpfully does NOT update the workflow.xml file – you should do this manually
2c. Note: Sharepoint does a lot of logging some helpful, some not. If you trawl through the logs, you’ll usually get a step in the right direction to tracking down your errors. The logs are by default in : %Program Files%\Common Files\Microsoft Shared\web server extensions\12\LOGS
3. Activity/workflow properties can be empty -  In the properties of each your activities/methods, you don’t need to fill in all of the details. In fact, most of them will be empty, e.g., a method doesn’t necessarily need a MethodInvoking method if you don’t need to do anything more complex with it. In fact, my experience is to be as minimal as possible. By setting some apparantly insignificant properties or asking VS to create your eventhandlers, you can end up with a lot of extra code that you just don’t need. Always pick through the codefile and identify things that can be simplified or removed.

I’ll add more as I come across them, but for now here is a useful link for basic workflowing in Sharepoint / MOSS 2007 and Visual Studio 2008 which has a lovely video you can watch.