public static void attachWorkflow(this List lst, ClientContext ctx, string cTemplateName) { try { Web web = lst.ParentWeb; ctx.Load(web, w => w.Url); ctx.ExecuteQuery(); System.Diagnostics.Trace.WriteLine(web.Url); WorkflowTemplate wt = GetWorkflowTemplate(web, cTemplateName); WorkflowAssociationCreationInformation wfc = new WorkflowAssociationCreationInformation { HistoryList = web.Lists.GetByTitle("Workflow History"), Name = cTemplateName, TaskList = web.Lists.GetByTitle("Workflow Tasks"), Template = wt }; WorkflowAssociation wf = lst.WorkflowAssociations.Add(wfc); wf.AllowManual = false; // is never updated wf.AutoStartChange = true; // is never wf.AutoStartCreate = true; // is never updated wf.Enabled = true; // is never updated //string assocData = GetAssociationXml(); // internal method // wf.AssociationData = assocData; // is never updated wf.Update(); ctx.Load(wf); ctx.ExecuteQuery(); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }
public static WorkflowAssociation CreateListWorkflowAssociation(this List list, WorkflowAssociationCreationInformation workflowAssociationCreation, bool allowManual, bool autoStartCreate, bool autoStartChange) { WorkflowAssociation wf = list.WorkflowAssociations.Add(workflowAssociationCreation); wf.AllowManual = allowManual; wf.AutoStartChange = autoStartCreate; wf.AutoStartCreate = autoStartChange; wf.Enabled = true; //string assocData = GetAssociationXml(); // internal method // wf.AssociationData = assocData; // is never updated wf.Update(); list.Context.Load(wf); list.Context.ExecuteQuery(); return(wf); }