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 void GivenTheListHasAWorkflowAssociated( /*Guid workflowId, * string workflowAssociationName, * string workflowHistoryListName, * string workflowTasksListName, * string associationData, * bool autoStartChange, * bool autoStartCreate*/ Table table) { var workflowId = Guid.Parse(table.Rows[0]["WorkflowId"].ToString()); var workflowAssociationName = table.Rows[0]["WorkflowAssociationName"]; var workflowHistoryListName = table.Rows[0]["WorkflowHistoryListName"]; var workflowTasksListName = table.Rows[0]["WorkflowTasksListName"]; var associationData = table.Rows[0]["AssociationData"]; var autoStartChange = Boolean.Parse(table.Rows[0]["AutoStartChange"]); var autoStartCreate = Boolean.Parse(table.Rows[0]["AutoStartCreate"]); using (var cc = Context.CreateClientContext()) { var list = cc.Web.Lists.GetByTitle(Context.LastListTitle); var workflowHistoryList = cc.Web.Lists.GetByTitle(workflowHistoryListName); var workflowTasksList = cc.Web.Lists.GetByTitle(workflowTasksListName); cc.Load(list); cc.Load(list.WorkflowAssociations); cc.Load(workflowHistoryList); cc.Load(workflowTasksList); cc.Load(cc.Web.WorkflowTemplates); cc.ExecuteQuery(); var assoc = list.WorkflowAssociations.SingleOrDefault(x => x.Name == workflowAssociationName); if (assoc == null) { var waci = new WorkflowAssociationCreationInformation(); waci.Template = cc.Web.WorkflowTemplates.Single(x => x.Id == workflowId); waci.Name = workflowAssociationName; waci.TaskList = workflowTasksList; waci.HistoryList = workflowHistoryList; assoc = list.WorkflowAssociations.Add(waci); } assoc.AutoStartChange = autoStartChange; assoc.AutoStartCreate = autoStartCreate; assoc.AssociationData = associationData; assoc.Update(); cc.ExecuteQuery(); } }
public static WorkflowAssociation CreateListWorkflowAssociation(this Web site, string listName, WorkflowTemplate workflowTemplate, string assocName, string workflowTasksListName, string workflowHistoryListName, bool allowManual, bool autoStartCreate, bool autoStartChange) { var wfc = new WorkflowAssociationCreationInformation { TaskList = site.Lists.GetByTitle(workflowTasksListName), HistoryList = site.Lists.GetByTitle(workflowHistoryListName), Name = assocName, Template = workflowTemplate }; List list = site.Lists.GetByTitle(listName); return(list.CreateListWorkflowAssociation(wfc, allowManual, autoStartCreate, autoStartChange)); }
static void Associate2010WorkflowWithList(ClientContext ctx, List data, List tasks, List history) { const string associationName = "SPWorkflowLatency.DispositionApproval"; var associations = data.WorkflowAssociations; ctx.Load(associations); ctx.ExecuteQuery(); if (associations.Any(a => a.Name == associationName)) { return; } var web = ctx.Web; var templates = web.WorkflowTemplates; ctx.Load(templates); ctx.ExecuteQuery(); var disposition = templates.Single(t => t.Name == "Disposition Approval"); var creationInfo = new WorkflowAssociationCreationInformation { TaskList = tasks, HistoryList = history, Template = disposition, Name = associationName }; var wa = data.WorkflowAssociations.Add(creationInfo); wa.AutoStartCreate = true; wa.AutoStartChange = true; wa.Enabled = true; wa.Update(); ctx.ExecuteQuery(); }
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); }
/// <summary> /// Imports new workflows to the target SharePoint. /// </summary> /// <exception cref="ElementsMigrationException">if migration fails</exception> private void ImportNewWorkflow() { Console.WriteLine("Import new WorkflowAssociations"); WorkflowAssociationCollection sourceWorkflowAssociations = this.GetAllWorkflowAssociationCollection(this.SourceClientContext); WorkflowAssociationCollection targetWorkflowAssociations = this.GetAllWorkflowAssociationCollection(this.TargetClientContext); if (sourceWorkflowAssociations.Count == 0) { Logger.AddMessage("no workflows to migrate..."); return; } HashSet <string> targetWorkflowNames = targetWorkflowAssociations.GetAllNames(); foreach (var sourceWorkflowAssociation in sourceWorkflowAssociations) { if (!targetWorkflowNames.Contains(sourceWorkflowAssociation.Name)) { Console.WriteLine("import new workflow '{0}'", sourceWorkflowAssociation.Name); Logger.AddMessage("import new workflow '" + sourceWorkflowAssociation.Name + "'"); WorkflowAssociationCreationInformation creationObject = new WorkflowAssociationCreationInformation(); creationObject.Name = sourceWorkflowAssociation.Name; creationObject.HistoryList = this.GetHistoryList(this.SourceClientContext); creationObject.TaskList = this.GetTaskList(this.SourceClientContext); creationObject.Template = this.GetTemplate(); WorkflowAssociation targetWorkflowAssociation = targetWorkflowAssociations.Add(creationObject); try { targetWorkflowAssociation.AllowManual = sourceWorkflowAssociation.AllowManual; } catch (PropertyOrFieldNotInitializedException) { } try { targetWorkflowAssociation.AutoStartChange = sourceWorkflowAssociation.AutoStartChange; } catch (PropertyOrFieldNotInitializedException) { } try { targetWorkflowAssociation.AutoStartCreate = sourceWorkflowAssociation.AutoStartCreate; } catch (PropertyOrFieldNotInitializedException) { } try { targetWorkflowAssociation.Enabled = sourceWorkflowAssociation.Enabled; } catch (PropertyOrFieldNotInitializedException) { } try { targetWorkflowAssociation.AssociationData = sourceWorkflowAssociation.AssociationData; } catch (PropertyOrFieldNotInitializedException) { } } else { Console.WriteLine("don't have to migrate workflow '{0}'", sourceWorkflowAssociation.Name); Logger.AddMessage("don't have to migrate workflow '" + sourceWorkflowAssociation.Name + "'"); } } try { this.TargetClientContext.ExecuteQuery(); } catch (Exception e) { Console.WriteLine("Exception during importing new Workflows.", e); Logger.AddMessage("Exception during importing new Workflows. Error = " + e.Message); throw new ElementsMigrationException("Exception during importing new Workflows.", e); } }