I've written an event receiver that programmatically kicks off a workflow, but it needs the id (guid) of the workflow to start. How do I go about obtaining the id of the workflow(s) I just created in Sharepoint Designer?
+1
A:
Since you created the workflow in SPD, you should know the list that the workflow is associated with and also the name of the workflow. Armed with that information, this should work:
Guid workflowGuid = list.WorkflowAssociations.GetAssociationByName(WORKFLOW_NAME, CULTURE_INFO).Id;
If you don't know or don't want to deal with the CultureInfo part, I suppose you could also loop through the SPWorkflowAssociationCollection and just find the right workflow, but this code seems cleaner to me.
Bryan Friedman
2008-10-14 17:37:39
I was toying around with the idea of finding the workflow by name, but the name isnt guaranteed unique and if someone renames the workflow, you have to recompile the event receiver. Oh, well. this will work. Thanks for showing me the GetAssociationByName method as well. I didnt even know it existed
Kilhoffer
2008-10-14 21:01:17
Yeah, I can see that being annoying. I suppose you could store the workflow name in a list or something to avoid having to recompile the event receiver. Of course then if the list gets renamed...... Ah, I love SharePoint. :)
Bryan Friedman
2008-10-14 22:23:58