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(
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.
Woo Hoo this is great !!
ReplyDeleteOh 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.
ReplyDeleteI 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.