public static void CreateAssociation(ref ClientContext clientContext, ref WorkflowServicesManager wfsm, Guid workflowDefinitionId, Guid listId, Guid historyListId, Guid taskListId) { WorkflowSubscriptionService subservice = wfsm.GetWorkflowSubscriptionService(); Console.WriteLine(); Console.WriteLine("Creating workflow association..."); WorkflowSubscription newSubscription = new WorkflowSubscription(clientContext) { DefinitionId = workflowDefinitionId, Enabled = true, Name = "Custom Association" + DateTime.Now }; // define startup options newSubscription.EventTypes = new List <string> { "ItemAdded", "ItemUpdated", "WorkflowStart" }; //define history & task list newSubscription.SetProperty("HistoryListId", historyListId.ToString()); newSubscription.SetProperty("TaskListId", taskListId.ToString()); //create association subservice.PublishSubscriptionForList(newSubscription, listId); clientContext.ExecuteQuery(); Console.WriteLine("Workflow association created!"); Console.ReadLine(); }
/// <summary> /// Create a new workflow association (subscription). /// </summary> public static void CreateAssociation(ref ClientContext clientConext, ref WorkflowServicesManager wfServicesManager, Guid definitionId, Guid listId, Guid historyListId, Guid taskListId) { WorkflowSubscriptionService subService = wfServicesManager.GetWorkflowSubscriptionService(); Console.WriteLine(); Console.WriteLine("Creating workflow association..."); // create new association (aka: subscription) WorkflowSubscription newSubscription = new WorkflowSubscription(clientConext) { DefinitionId = definitionId, Enabled = true, Name = "Custom Association " + DateTime.Now }; // define startup options // automatic start options = ItemAdded & ItemUpdated // manual start = WorkflowStart newSubscription.EventTypes = new List <string> { "ItemAdded", "ItemUpdated", "WorkflowStart" }; // define the history & task associated lists newSubscription.SetProperty("HistoryListId", historyListId.ToString()); newSubscription.SetProperty("TaskListId", taskListId.ToString()); // OPTIONAL: if any values submitted by association form, add as properties here newSubscription.SetProperty("Prop1", "Value1"); newSubscription.SetProperty("Prop2", "Value2"); // create the association subService.PublishSubscriptionForList(newSubscription, listId); // creates association on list //subService.PublishSubscription(newSubscription); // creates association on current site clientConext.ExecuteQuery(); Console.WriteLine("Workflow association created!"); }