Associating workflows to lists are pretty simple.
You will need the following:
Task List - Out of the box list
WorkFlowHistory List - Out of the box list
Workflow List - Workflow associate to this list
SPSecurity.RunWithElevatedPrivileges(delegate()
{
web.AllowUnsafeUpdates = true;
SPList taskList;
SPList workflowHistoryList;
SPList indexItemList = web.Lists[Constants.IndexItemList];
try
{
taskList = web.Lists[Constants.WFTasks];
}
catch
{
taskList = web.Lists[web.Lists.Add(Constants.WFTasks, Constants.WFTasks, SPListTemplateType.Tasks)];
}
try
{
workflowHistoryList = web.Lists[Constants.WFHistory];
}
catch
{
workflowHistoryList = web.Lists[web.Lists.Add(Constants.WFHistory, Constants.WFHistory, SPListTemplateType.WorkflowHistory)];
}
SPWorkflowTemplate template = web.WorkflowTemplates.GetTemplateByBaseID(new Guid(Constants.workFlowTemplateId));
SPWorkflowAssociation association = SPWorkflowAssociation.CreateListAssociation(template, template.Name, taskList, workflowHistoryList);
association.AllowManual = true;
association.AutoStartChange = true;
association.AutoStartCreate = true;
indexItemList.WorkflowAssociations.Add(association);
indexItemList.Update();
web.AllowUnsafeUpdates = false;
web.Update();
});
Workflow start properties may vary, please change as you see fit.
Over the years, I’ve performed many technical roles — from hands-on engineering to enterprise architecture — and always found joy in sharing ideas through blogging. After a bit of a hiatus from blogging, I thought I’d start again and try my luck at putting thoughts out there. My hope is to spark collaboration, challenge assumptions, and maybe even help us do things a little better. So here are my ramblings for now…
Showing posts with label WorkFlow Associations. Show all posts
Showing posts with label WorkFlow Associations. Show all posts
Monday, July 18, 2011
Subscribe to:
Posts (Atom)