views:

602

answers:

1

I've created a SharePoint 2007 Sequential Workflow and am trying to activate two workflows (one approval and one feedback) programmatically.

workflowProperties.Site.WorkflowManager.StartWorkflow(workflowProperties.Item, association, association.AssociationData, true);

I use this code to start the work flow and the association is created on the fly. The problem arises when I am trying to access the other lists in order to create the association object.

SPList approvalsList = workflowProperties.Web.Lists["Tasks"];
SPList historyList = workflowProperties.Web.Lists["Workflow History"];

This is what I get:

Unable to cast COM object of type 'Microsoft.SharePoint.Library.SPRequestInternalClass' to interface type 'Microsoft.SharePoint.Library.ISPRequest'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{BDEADEBE-C265-11D0-BCED-00A0C90AB50F}' failed due to the following error: Bad variable type. (Exception from HRESULT: 0x80020008 (DISP_E_BADVARTYPE)).

The only list that is accessible is through workflowProperties.List. How do I make this work, or are there any better ways to invoke another workflow in a custom workflow?

A: 

I use Useful Sharepoint Designer Custom Workflow Activities to start another workflow.
If you can't use it as-is, have a look at its source code. It doesn't look like they manually set the task and history lists: http://spdactivities.codeplex.com/SourceControl/changeset/view/22637#201408

Kobi
I'll accept this answer although I can't really use it as my project has been submitted =) Also, I did quite a bit of my own searching before I came to SO; it was the last resort besides using the hack which we ended up using (actually more of a compromise than anything). Also, the problem with invoking two workflows is that you have to be in the same thread or something. For some reason you are not able to access the exact SP context from a custom workflow as it does not run in the same executing thread. I don't know if your answer does work but let's hope it helps someone else down the road.
Jaryl
Hey Jaryl. Sorry I couldn't help. While I like the accepted answer, a better practice would be to add and accept your own answer - it did solve your problem, and more likely to help someone :)
Kobi