I am running a SharePoint workflow programmatically from a SharePoint event receiver by calling workflowManager.StartWorkflow().
The workflow is setting some workflow variables during execution. Is there a way to access the last value of these variables after the workflow has terminated (e.g., the call to StartWorkflow() returns)?
Here's my sample code that demonstrates my intent:
public override void ItemAdded(SPItemEventProperties properties)
{
SPWorkflow workflow = null;
SPWorkflowManager workflowManager = null;
try
{
base.ItemAdded(properties);
workflowManager = properties.OpenWeb().Site.WorkflowManager;
var workflowAssociation = properties.ListItem.ParentList.WorkflowAssociations[0];
workflow = workflowManager.StartWorkflow(properties.ListItem, workflowAssociation, "<Data></Data>");
// I can read any fields that were updated by the WF
SPListItem item = properties.ListItem.ParentList.GetItemById(properties.ListItemId);
string validationResult = (string) item["ValidationResult"];
// how can I access any workflow variables created during execution?
}
catch (Exception ex)
{
Debug.WriteLine(ex);
if (workflow != null && workflowManager != null)
{
SPWorkflowManager.CancelWorkflow(workflow);
}
throw;
}
}