Pages

Thursday, November 5, 2009

SharePoint Designer and Workflows...beware

It seems that no matter how many times I'm disappointed using SharePoint Designer 2007 I still find myself using it. The ability to quickly browse content on my SharePoint site, copy content into my Visual Studio project and quickly create Workflows that are attached to lists...**halt**... That's what I thought about 2 weeks ago until it came time to migrate the site I was currently working to another web application. Little did I know that workflows, created in SharePoint Designer, are assigned to lists using the lists's GUID (which makes perfect sense).

Okay, enough of the background. If you're like me and you get into something where you end up getting stuck (classic tar-baby) you won't give up without a fight. Well, fight hard I did. It turns out that it IS possible to reattach the workflow to its list after exporting your SharePoint site to a new site collection...the answer in a nutshell... make a call to SharePoint's web part service (duh...obviously...not).

Here's what I did, in a nutshell.

1) Create a feature event receiver to attach the workflow to the new list.
2) Open the workflow configuration files (usually stored in the "Workflows" list in your site) and replace all the list GUIDs from the old site with the GUIDs from the new site.
3) Call the SharePoint web part service to reassociate the workflow with the list. Here is a code sample for this step.

WebPartPagesWebService service = new WebPartPagesWebService();
service.Url = String.Format("{0}/{1}", SPWeb.Url, "_vti_bin/webpartpages.asmx");
service.UseDefaultCredentials = true;
service.ValidateWorkflowMarkupAndCreateSupportObjects(, null, , "2");
service.AssociateWorkflowMarkup(cfgFile.Url, "V" + cfgFile.UIVersionLabel);

**Important thing to note is the service will not associate the workflow with the list unless the version number of the config. file is greater than what is there currently. In other words you need to make sure the version of the workflow configuration file increases before calling the service to associate the workflow with the list.

2 comments :

  1. Oh my god, thank you soooooo much. I was researching this all day yesterday...I figured where the workflow fiels (XOML, etc.) were and I changed all the GUIDs in them, but I couldn't figure out how to associate the stupid thing back to the list.

    I can't believe that you have to use (of all things) the WebPartPagesWebService...so weird. I also can't believe that all the third party site migration tools I've tried don't incorporate this when you try to use them to split up a site collection.

    ReplyDelete

I always welcome constructive feedback. Thanks.