Custom SharePoint Workflow MetaData
Have you ever wondered what VooDoo is going on in the “MetaData” element in the sharepoint workflow template definition (Workflow.xml)? No? Well I have.
It’s not documented, but you can read it using the SharePoint Workflow API. (The method you can call is documented, that is, listed, in the MSDN documentation. It’s not actually explained, or as I would say it, ‘documented.’)
If you see our friend, the class SPWorkflowTemplate on MSDN, you’ll notice that the Item property is there, but it’s not telling you that you basically just use that to pull the metadata.
So, from within a workflow template code block, how would you access this magical SPWorkflowTemplate? There are a bunch of ways, but the simplest is to use the SPWorkflowProperties object that’s bound to your OnWorkflowActivated activity.
string GetMetaDataString(string valueName) {
// get the template.
SPWorkflowTemplate template = workflowProperties.Workflow.ParentAssociation.BaseTemplate;
// WARNING: check the value for null before .ToString()
// in C# there is only an indexer that aliases the .Item
return template[valueName].ToString();
}
Well what’s that good for? I’m not sure! That’s really up to you. I did see a couple of cool guys from the Ted Pattison Group using it to make a framework for doing effective workflow in WSS 3. (Here’s a link, it’s called WSS3Workflow, and it’s great.)
I always end up putting things in the web.config, but some of the more static things I might never change, but technically want to be able to without recompiling the thing, might go in there. I don’t know. I just thought it was cool.
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Many thanks! It worked perfectly on my blog