private void iInstallListsWorkflowsInstall(SPList oList, string sName, string sDisplayName, SPList oTaskList, SPList oHistoryList, XmlNode ndWorkflow) { SPWorkflowAssociation assocation = null; var bAllowManual = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndWorkflow, "AllowManual"), out bAllowManual); var bStartOnCreate = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndWorkflow, "StartOnCreate"), out bStartOnCreate); var bStartOnChange = false; bool.TryParse(ApplicationInstallerHelpers.getAttribute(ndWorkflow, "StartOnChange"), out bStartOnChange); foreach (SPWorkflowTemplate template in oWeb.WorkflowTemplates) { if (template.Name == sName) { assocation = SPWorkflowAssociation.CreateListAssociation(template, sDisplayName, oTaskList, oHistoryList); break; } } if (assocation != null) { assocation.AllowManual = bAllowManual; assocation.AutoStartChange = bStartOnChange; assocation.AutoStartCreate = bStartOnCreate; oList.WorkflowAssociations.Add(assocation); } }
private void StartListWorkflow() { SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)]; this.Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData()); SPUtility.Redirect(this.workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current); }
public static void AssociateWorflow(SPWeb web, string workflowTemplateBaseGuid, string workflowAssociationName) { //string workflowTemplateBaseGuid = "0b5d7c6b-2764-45dc-8fc1-33fa98145d1c"; //string workflowAssociationName = "Odchudzanie bazy danych"; SPWorkflowTemplateCollection workflowTemplates = web.WorkflowTemplates; SPWorkflowTemplate workflowTemplate = workflowTemplates.GetTemplateByBaseID(new Guid(workflowTemplateBaseGuid)); if (workflowTemplate != null) { // Create the workflow association SPList taskList = EnsureListExist(web, workflowTaskListName); SPList historyList = EnsureListExist(web, workflowHistoryListName); SPWorkflowAssociation workflowAssociation = web.WorkflowAssociations.GetAssociationByName(workflowAssociationName, CultureInfo.InvariantCulture); if (workflowAssociation == null) { workflowAssociation = SPWorkflowAssociation.CreateWebAssociation(workflowTemplate, workflowAssociationName, taskList, historyList); workflowAssociation.AllowManual = true; //workflowAssociation.Enabled = true; - nie wiem dlaczego ale ta pozycja wywala błąd. web.WorkflowAssociations.Add(workflowAssociation); } } }
private void AssociateSiteContentTypeWorkflow() { SPContentType contentType = Web.ContentTypes[this.associationParams.ContentTypeId]; SPWorkflowAssociation association; if (this.associationParams.AssociationGuid == Guid.Empty) { association = SPWorkflowAssociation.CreateWebContentTypeAssociation( Web.WorkflowTemplates[new Guid(this.associationParams.BaseTemplate)], this.associationParams.AssociationName, this.associationParams.TaskListName, this.associationParams.HistoryListName); PopulateAssociationParams(association); contentType.WorkflowAssociations.Add(association); } else { association = contentType.WorkflowAssociations[this.associationParams.AssociationGuid]; association.TaskListTitle = this.associationParams.TaskListName; association.HistoryListTitle = this.associationParams.HistoryListName; PopulateAssociationParams(association); contentType.WorkflowAssociations.Update(association); } if (this.associationParams.ContentTypePushDown) { contentType.UpdateWorkflowAssociationsOnChildren(false); } }
private void AssociateListWorkflow() { SPList targetList = Web.Lists[this.associationParams.TargetListGuid]; SPWorkflowAssociation association; if (associationParams.AssociationGuid == Guid.Empty) { association = SPWorkflowAssociation.CreateListAssociation( Web.WorkflowTemplates[new Guid(this.associationParams.BaseTemplate)], this.associationParams.AssociationName, Web.Lists[this.associationParams.TaskListGuid], Web.Lists[this.associationParams.HistoryListGuid]); PopulateAssociationParams(association); targetList.WorkflowAssociations.Add(association); } else { association = targetList.WorkflowAssociations[this.associationParams.AssociationGuid]; association.SetTaskList(Web.Lists[this.associationParams.TaskListGuid]); association.SetHistoryList(Web.Lists[this.associationParams.HistoryListGuid]); PopulateAssociationParams(association); targetList.WorkflowAssociations.Update(association); } SetDefaultContentApprovalWorkflow(targetList, association); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(__Context.Site.ID)) { using (SPWeb web = site.AllWebs[__Context.Web.ID]) { SPList list = web.Lists[Helper.GetListGuid(__Context, ListId)]; SPListItem item = list.Items.GetItemById(__ListItem); SPWorkflowAssociation assoc = list.WorkflowAssociations.GetAssociationByName(WorkflowName, Thread.CurrentThread.CurrentCulture); if (assoc == null) { throw new NullReferenceException("Workflow association not found"); } if (String.IsNullOrEmpty(EventData)) { web.Site.WorkflowManager.StartWorkflow(item, assoc, assoc.AssociationData); } else { web.Site.WorkflowManager.StartWorkflow(item, assoc, EventData); } } } }); return(ActivityExecutionStatus.Closed); }
public static SPWorkflowAssociation EnsureWorkflowAssociation(SPWorkflowAssociationCollection collection, Guid workflowBaseId, SPWorkflowAssociationCreator createDelegate, out bool associationUpdated) { CommonHelper.ConfirmNotNull(collection, "collection"); CommonHelper.ConfirmNotNull(createDelegate, "createDelegate"); associationUpdated = false; SPWeb targetWeb = collection.ParentWeb; SPWorkflowAssociation wfAssoc = collection.GetAssociationByBaseIDSafe(workflowBaseId); if (wfAssoc == null) { SPWorkflowTemplate wfTemplate = targetWeb.WorkflowTemplates[workflowBaseId]; if (wfTemplate == null) { throw new ArgumentOutOfRangeException("workflowBaseId", "Workflow template with the specified base ID does not exist in this site"); } SPList taskList = EnsureList(targetWeb, SPListTemplateType.Tasks, SPResource.GetString("DefaultWorkflowTaskListName", new object[0])); SPList historyList = EnsureList(targetWeb, SPListTemplateType.WorkflowHistory, SPResource.GetString("DefaultWorkflowHistoryListName", new object[0])); wfAssoc = createDelegate(wfTemplate, wfTemplate.Name, taskList, historyList); collection.Add(wfAssoc); associationUpdated = true; } if (!wfAssoc.Enabled) { wfAssoc.Enabled = true; collection.Update(wfAssoc); associationUpdated = true; } return(wfAssoc); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb web = properties.Feature.Parent as SPWeb; IConfigManager hierarchicalConfig = SharePointServiceLocator.Current.GetInstance <IConfigManager>(); hierarchicalConfig.SetInPropertyBag(Constants.SubSiteCreationConfigSiteKey, web.Url, SPFarm.Local); SPList taskList = web.Lists[taskListName]; SPList historyList = web.Lists[workflowHistoryName]; SPList subSiteCreationRequestList = web.Lists[subSiteRequestsListName]; var existingAssociation = subSiteCreationRequestList.WorkflowAssociations.GetAssociationByName(workflowTemplateName, CultureInfo.CurrentCulture); if (existingAssociation == null) { SPWorkflowManager workflowManager = web.Site.WorkflowManager; SPWorkflowTemplateCollection templates = workflowManager.GetWorkflowTemplatesByCategory(web, null); SPWorkflowTemplate template = templates.GetTemplateByBaseID(workflowTemplateId); SPWorkflowAssociation association = SPWorkflowAssociation.CreateListAssociation(template, template.Name, taskList, historyList); association.AllowManual = true; association.AutoStartCreate = true; subSiteCreationRequestList.AddWorkflowAssociation(association); subSiteCreationRequestList.Update(); association.Enabled = true; } ServiceLocatorConfig typeMappings = new ServiceLocatorConfig(); typeMappings.RegisterTypeMapping <IBusinessEventTypeConfigurationRepository, BusinessEventTypeConfigurationRepository>(); typeMappings.RegisterTypeMapping <ISubSiteCreationRequestRepository, SubSiteCreationRequestsRepository>(); }
public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWeb web = properties.Feature.Parent as SPWeb; if (web != null) { SPList taskList = web.Lists[Lists.RegistrationApprovalTasks]; SPList historyList = web.Lists[Lists.WorkflowHistory]; SPList registrationList = web.Lists[Lists.Registrations]; SPWorkflowAssociation existingAssociation = null; existingAssociation = registrationList.WorkflowAssociations.GetAssociationByName(WorkflowTemplates.RegistrationApprovalNameV2, CultureInfo.CurrentCulture); if (existingAssociation == null) { //Create a worklow manager and associate the Course Registration Approval Workflow template //to our Registrations list. SPWorkflowManager workflowManager = web.Site.WorkflowManager; SPWorkflowTemplateCollection templates = workflowManager.GetWorkflowTemplatesByCategory(web, null); SPWorkflowTemplate template = templates.GetTemplateByBaseID(new Guid(WorkflowTemplates.RegistrationApprovalBaseIdV2)); SPWorkflowAssociation association = SPWorkflowAssociation.CreateListAssociation(template, template.Name, taskList, historyList); association.AllowManual = true; association.AutoStartCreate = true; registrationList.AddWorkflowAssociation(association); registrationList.Update(); association.Enabled = true; } } }
private void MapProperties(WorkflowAssociationDefinition definition, SPWorkflowAssociation association) { if (!string.IsNullOrEmpty(definition.Description)) { association.Description = definition.Description; } if (!string.IsNullOrEmpty(definition.AssociationData)) { association.AssociationData = definition.AssociationData; } if (definition.AllowManual.HasValue) { association.AllowManual = definition.AllowManual.Value; } if (definition.AutoStartChange.HasValue) { association.AutoStartChange = definition.AutoStartChange.Value; } if (definition.AutoStartCreate.HasValue) { association.AutoStartCreate = definition.AutoStartCreate.Value; } if (definition.Enabled.HasValue) { association.Enabled = definition.Enabled.Value; } }
/// <summary> /// Bind workflow /// </summary> /// <param name="web"></param> /// <param name="contentTypeName"></param> /// <param name="workflowName"></param> public static void BindWorkflow(SPWeb web, string contentTypeName, string workflowName) { SPContentType siteContentType = web.ContentTypes[contentTypeName]; string taskListTitle = ApplicationConfig.TaskListName; string historyListTitle = ApplicationConfig.HistoryListName; SPWorkflowAssociation wfAssoc = null; // Get a template. SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates.Cast <SPWorkflowTemplate>().FirstOrDefault(wft => wft.Name == workflowName); // Add the association to the content type or update it if it already exists. if ((wfAssoc = siteContentType.WorkflowAssociations.GetAssociationByName(workflowName, web.Locale)) == null) { wfAssoc = SPWorkflowAssociation.CreateWebContentTypeAssociation(workflowTemplate, workflowName, taskListTitle, historyListTitle); siteContentType.WorkflowAssociations.Add(wfAssoc); } else { siteContentType.WorkflowAssociations.Update(wfAssoc); } // Propagate to children of this content type. siteContentType.UpdateWorkflowAssociationsOnChildren(false, // Do not generate full change list true, // Push down to derived content types true, // Push down to list content types false); // Do not throw exception if sealed or readonly }
public void FeatureActivatedTest() { SPFeatureReceiverProperties properties = Isolate.Fake.Instance <SPFeatureReceiverProperties>(Members.ReturnRecursiveFakes); SPFarm fakeSPFarm = Isolate.Fake.Instance <SPFarm>(Members.ReturnRecursiveFakes); Isolate.WhenCalled(() => SPFarm.Local).WillReturn(fakeSPFarm); Hashtable farmProperties = new Hashtable(); Isolate.WhenCalled(() => fakeSPFarm.Properties).WillReturn(farmProperties); MockConfigManager.ReturnValue = "http://localhost"; SharePointServiceLocator.ReplaceCurrentServiceLocator(new ActivatingServiceLocator() .RegisterTypeMapping <IConfigManager, MockConfigManager>() .RegisterTypeMapping <ILogger, MockLogger>()); SPWeb fakeSPWeb = Isolate.Fake.Instance <SPWeb>(Members.ReturnRecursiveFakes); Isolate.WhenCalled(() => properties.Feature.Parent).WillReturn(fakeSPWeb); SPWorkflowAssociation fakeAssociation = Isolate.Fake.Instance <SPWorkflowAssociation>(Members.ReturnRecursiveFakes); Isolate.WhenCalled(() => SPWorkflowAssociation.CreateListAssociation(null, "", null, null)).WillReturn(fakeAssociation); FeatureReceiver target = new FeatureReceiver(); target.FeatureActivated(properties); Isolate.Verify.WasCalledWithAnyArguments(() => fakeSPWeb.Lists["Sub Site Creation Requests"].Update()); }
private void StartSiteWorkflow() { SPWorkflowAssociation association = this.Web.WorkflowAssociations[new Guid(this.associationGuid)]; this.Web.Site.WorkflowManager.StartWorkflow((object)null, association, GetInitiationData(), SPWorkflowRunOptions.Synchronous); SPUtility.Redirect(this.Web.Url, SPRedirectFlags.UseSource, HttpContext.Current); }
private void AssociateListContentTypeWorkflow() { SPContentType contentType = Web.Lists[associationParams.TargetListGuid].ContentTypes[associationParams.ContentTypeId]; SPWorkflowAssociation association; if (associationParams.AssociationGuid == Guid.Empty) { association = SPWorkflowAssociation.CreateListContentTypeAssociation( Web.WorkflowTemplates[new Guid(this.associationParams.BaseTemplate)], this.associationParams.AssociationName, Web.Lists[this.associationParams.TaskListGuid], Web.Lists[this.associationParams.HistoryListGuid]); PopulateAssociationParams(association); contentType.WorkflowAssociations.Add(association); } else { association = contentType.WorkflowAssociations[this.associationParams.AssociationGuid]; association.SetTaskList(Web.Lists[this.associationParams.TaskListGuid]); association.SetHistoryList(Web.Lists[this.associationParams.HistoryListGuid]); PopulateAssociationParams(association); contentType.WorkflowAssociations.Update(association); } if (this.associationParams.ContentTypePushDown) { contentType.UpdateWorkflowAssociationsOnChildren(false); } }
private void DeployListWorkflowAssociationDefinition(ListModelHost modelHost, SPList list, WorkflowAssociationDefinition definition) { var existingWorkflowAssotiation = FindExistringWorkflowAssotiation(modelHost, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = existingWorkflowAssotiation, ObjectType = typeof(SPWorkflowAssociation), ObjectDefinition = definition, ModelHost = modelHost }); bool isNew = false; if (existingWorkflowAssotiation == null) { var workflowTemplate = GetWorkflowTemplate(modelHost, definition); if (workflowTemplate == null) { throw new SPMeta2Exception( string.Format("Cannot find workflow template by definition:[{0}]", definition)); } existingWorkflowAssotiation = SPWorkflowAssociation.CreateListAssociation(workflowTemplate, definition.Name, list.ParentWeb.Lists[definition.TaskListTitle], list.ParentWeb.Lists[definition.HistoryListTitle]); isNew = true; } MapProperties(definition, existingWorkflowAssotiation); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = existingWorkflowAssotiation, ObjectType = typeof(SPWorkflowAssociation), ObjectDefinition = definition, ModelHost = modelHost }); if (isNew) { list.WorkflowAssociations.Add(existingWorkflowAssotiation); list.Update(); } else { list.WorkflowAssociations.Update(existingWorkflowAssotiation); } }
public SPWorkflowAssociationInstance(ObjectInstance prototype, SPWorkflowAssociation workflowAssociation) : this(prototype) { if (workflowAssociation == null) { throw new ArgumentNullException("workflowAssociation"); } m_workflowAssociation = workflowAssociation; }
private void StartListWorkflow() { TraceEvent("Entering CloseManyIPRAccountsForm.StartListWorkflow", 207, TraceSeverity.Monitorable); SPWorkflowAssociation association = this.workflowList.WorkflowAssociations[new Guid(this.associationGuid)]; this.Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData()); TraceEvent(" CloseManyIPRAccountsForm.StartListWorkflow Redirect to: " + this.workflowList.DefaultViewUrl, 210, TraceSeverity.Verbose); bool _redirectResult = SPUtility.Redirect(this.workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, HttpContext.Current); TraceEvent(String.Format("CloseManyIPRAccountsForm.StartListWorkflow Redirect result: {0}", _redirectResult), 212, TraceSeverity.Verbose); }
internal string Serialize(SPWorkflowAssociation _wa) { using (MemoryStream stream = new MemoryStream()) { XmlSerializer serializer = new XmlSerializer(typeof(POLibraryWorkflowAssociationData)); serializer.Serialize(stream, this); stream.Position = 0; byte[] bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); return(Encoding.UTF8.GetString(bytes)); } }
public WorkflowAssociationNode(object parent, SPWorkflowAssociation workflowAssociation) { this.Tag = workflowAssociation; this.SPParent = parent; Setup(); //if (workflowAssociation.p .SPParent this.Definition.Properties.Count > 0) //{ // this.Nodes.Add(new ExplorerNodeBase("Dummy")); //} }
private void FetchAssociationInfo() { SPWorkflowAssociationCollection wac; m_baseTemplate = Web.WorkflowTemplates[new Guid(Request.Params["WorkflowDefinition"])]; m_assocTemplate = null; // figure out whether or not this is associating with a content type or a list, // and get the association collection. Also set the return page values. if (m_ct != null) // associating w/ a content type { wac = m_ct.WorkflowAssociations; hlReturn.Text = m_ct.Name; hlReturn.NavigateUrl = "ManageContentType.aspx" + m_strQueryParams; } else // associating w/ a list { List.Permissions.CheckPermissions(SPRights.ManageListPermissions); wac = List.WorkflowAssociations; hlReturn.Text = List.Title; hlReturn.NavigateUrl = List.DefaultViewUrl; } if (wac == null || wac.Count < 0) { throw new SPException("No Associations Found"); } //Set the general workflow properties m_autoStartCreate = (Request.Params["AutoStartCreate"] == "ON"); m_autoStartChange = (Request.Params["AutoStartChange"] == "ON"); m_allowManual = (Request.Params["AllowManual"] == "ON"); m_bLockItem = (Request.Params["LockItem"] == "ON"); m_setDefault = (Request.Params["SetDefault"] == "ON"); m_updateLists = (Request.Params["UpdateLists"] == "TRUE"); // check if workflow association already exists. string strGuidAssoc = Request.Params["GuidAssoc"]; if (strGuidAssoc != string.Empty) { m_assocTemplate = wac[new Guid(strGuidAssoc)]; } // Check for a duplicate name. Note that we do this both on initial load and on // postback. The reason we do it on postback is that some other user may have // added a workflow by this name since the last time we checked. SPWorkflowAssociation dupTemplate = wac.GetAssociationByName(m_workflowName, Web.Locale); if (dupTemplate != null && (m_assocTemplate == null || m_assocTemplate.Id != dupTemplate.Id)) { // throw an exception if there is a template with the same name already throw new SPException("Duplicate workflow name is detected."); } }
public SPWorkflowAssociationInstance ImportFromXml(SPWebInstance rootWeb, string xml) { if (rootWeb == null) { throw new JavaScriptException(this.Engine, "Error", "A web must be supplied as the first argument."); } var result = SPWorkflowAssociation.ImportFromXml(rootWeb.Web, xml); return(result == null ? null : new SPWorkflowAssociationInstance(this.Engine.Object.InstancePrototype, result)); }
private void DeployListWorkflowAssociationDefinition(ListModelHost modelHost, SPList list, WorkflowAssociationDefinition definition) { var existingWorkflowAssotiation = FindExistringWorkflowAssotiation(modelHost, definition); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioning, Object = existingWorkflowAssotiation, ObjectType = typeof(SPWorkflowAssociation), ObjectDefinition = definition, ModelHost = modelHost }); bool isNew = false; if (existingWorkflowAssotiation == null) { var workflowTemplate = GetWorkflowTemplate(modelHost, definition); existingWorkflowAssotiation = SPWorkflowAssociation.CreateListAssociation(workflowTemplate, definition.Name, list.Lists[definition.TaskListTitle], list.Lists[definition.HistoryListTitle]); isNew = true; } MapProperties(definition, existingWorkflowAssotiation); InvokeOnModelEvent(this, new ModelEventArgs { CurrentModelNode = null, Model = null, EventType = ModelEventType.OnProvisioned, Object = existingWorkflowAssotiation, ObjectType = typeof(SPWorkflowAssociation), ObjectDefinition = definition, ModelHost = modelHost }); if (isNew) { list.WorkflowAssociations.Add(existingWorkflowAssotiation); } else { // ?? } }
public SPWorkflowAssociationInstance CreateWebContentTypeAssociation(SPWorkflowTemplateInstance template, string name, string taskListName, string historyListName) { if (template == null) { throw new JavaScriptException(this.Engine, "Error", "A workflow template must be supplied as the first argument."); } var result = SPWorkflowAssociation.CreateWebContentTypeAssociation(template.SPWorkflowTemplate, name, taskListName, historyListName); return(result == null ? null : new SPWorkflowAssociationInstance(this.Engine.Object.InstancePrototype, result)); }
private void AssociateWithWorkFlows(string[] workFlows, SPSite curSite, SPWeb curWeb) { List <SPList> docLibs = new List <SPList>(); SPWorkflowTemplate baseTemplate = null; SPWorkflowTemplate wfTemplate = null; // our template we store in PropertyBag SPList caseDocs = curWeb.GetListByInternalName(eCaseConstants.ListInternalNames.REFERRAL_DOCUMENTS); SPList relatedDocs = curWeb.GetListByInternalName(eCaseConstants.ListInternalNames.INVESTIGATION_DOCUMENTS); SPList finishedWorkProducts = curWeb.GetListByInternalName(eCaseConstants.ListInternalNames.SDO_DOCUMENTS); docLibs.Add(caseDocs); docLibs.Add(relatedDocs); docLibs.Add(finishedWorkProducts); var taskList = curWeb.GetListByInternalName("Tasks List"); var historyList = curWeb.GetListByInternalName("Workflow History List"); if (historyList == null) { var hlGuid = curWeb.Lists.Add("Workflow History List", string.Empty, SPListTemplateType.WorkflowHistory); historyList = curWeb.Lists.GetList(hlGuid, false); } if (taskList == null) { var tlGuid = curWeb.Lists.Add("Tasks List", string.Empty, SPListTemplateType.Tasks); taskList = curWeb.Lists.GetList(tlGuid, false); } foreach (string wfName in workFlows) { wfTemplate = curWeb.WorkflowTemplates.GetTemplateByName(wfName, CultureInfo.CurrentCulture); if (wfTemplate != null) { baseTemplate = wfTemplate; baseTemplate.StatusColumn = false; foreach (SPList docLib in docLibs) { if (docLib.WorkflowAssociations.GetAssociationByBaseID(baseTemplate.Id) == null) { SPWorkflowAssociation assoc = SPWorkflowAssociation.CreateListContentTypeAssociation(baseTemplate, baseTemplate.Name, taskList, historyList); assoc.AllowManual = true; assoc.AutoStartCreate = false; docLib.WorkflowAssociations.Add(assoc); assoc.Enabled = true; } } } } }
private void PopulateFormFields(SPWorkflowAssociation existingAssociation) { string data = existingAssociation.AssociationData; if (!string.IsNullOrEmpty(data)) { XmlDocument doc = new XmlDocument(); doc.LoadXml(data); XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD"); XmlNode node = doc.SelectSingleNode("/my:myFields/my:EstimationManager", nsmgr); EstimationManager.Text = node.InnerText; } }
private static void EnsureWorkflowAssociationCT(SPContentType ct, string workflowTemplateName, string associationName) { SPSite site = ct.ParentWeb.Site; SPWeb web = site.OpenWeb(); var lcid = (int)web.Language; var defaultCulture = new CultureInfo(lcid); // Create the workflow association SPList taskList = EnsureListExist(web, workflowTaskListName); SPList historyList = EnsureListExist(web, workflowHistoryListName); // Get a template SPWorkflowTemplate workflowTemplate = null; foreach (SPWorkflowTemplate template in web.WorkflowTemplates) { workflowTemplate = template; if (workflowTemplate.Name.Equals(workflowTemplateName)) { break; } } SPWorkflowAssociation workflowAssociation = SPWorkflowAssociation.CreateWebContentTypeAssociation(workflowTemplate, associationName, workflowTaskListName, workflowHistoryListName); //ElasticEmail.EmailGenerator.SendMail("wartość zmiennej", ct.WorkflowAssociations.GetAssociationByName(workflowAssociation.Name, web.Locale).Name); // Add the association to the content type or update it if it already exists. if (ct.WorkflowAssociations.GetAssociationByName(workflowAssociation.Name, web.Locale) == null) { //ElasticEmail.EmailGenerator.SendMail("ct:add", ""); ct.WorkflowAssociations.Add(workflowAssociation); } else { //ElasticEmail.EmailGenerator.SendMail("ct:update", ""); //ct.WorkflowAssociations.Update(workflowAssociation); ct.WorkflowAssociations.UpdateAssociationsToLatestVersion(); } // Propagate to children of this content type. ct.UpdateWorkflowAssociationsOnChildren(false, // Do not generate full change list true, // Push down to derived content types true, // Push down to list content types false); // Do not throw exception if sealed or readonly web.Dispose(); site.Dispose(); }
private void InitializeParams() { // Check if the page is loaded for first time if (ViewState["associationParams"] == null) { InitializeAssociationParams(); ViewState["associationParams"] = this.associationParams; SPWorkflowAssociation existingAssociation = GetExistingAssociation(); PopulateFormFields(existingAssociation); } else { this.associationParams = (AssociationParams)ViewState["associationParams"]; } }
public static SPWorkflowAssociation CreateListWorkflowAssociation(this SPContentType contentType, SPWorkflowTemplate workflowTemplate, string assocName, SPList workflowTasksList, SPList workflowHistoryList, bool overwrite = false, Action <SPWorkflowAssociation> action = null) { if (workflowTemplate == null) { throw new ArgumentNullException("workflowTemplate"); } SPWorkflowAssociation workflowAssociation = null; // create the association SPWorkflowAssociation assoc = SPWorkflowAssociation.CreateListContentTypeAssociation( workflowTemplate, assocName, workflowTasksList, workflowHistoryList); if (action != null) { action(assoc); } //apply the association to the list if (contentType != null) { if (overwrite) { SPWorkflowAssociation dupWfAssoc = contentType.WorkflowAssociations.GetAssociationByName(assocName, contentType.ParentWeb.Locale); if (dupWfAssoc != null) { if (dupWfAssoc.BaseId == workflowTemplate.Id) { contentType.WorkflowAssociations.Remove(dupWfAssoc); } else { throw new SPException(string.Format("Duplicate workflow name \"{0}\" is detected.", assocName)); } } } workflowAssociation = contentType.WorkflowAssociations.Add(assoc); } return(workflowAssociation); }
/// <summary> /// Adds the workflow associations. /// </summary> /// <param name="targetCT">The target content type.</param> /// <param name="sourceCT">The source content type.</param> private void AddWorkflowAssociations(SPContentType targetCT, SPContentType sourceCT) { // Remove the default workflows - we're going to add from the source. while (targetCT.WorkflowAssociations.Count > 0) { targetCT.WorkflowAssociations.Remove(targetCT.WorkflowAssociations[0]); } // Add workflows. foreach (SPWorkflowAssociation wf in sourceCT.WorkflowAssociations) { Logger.Write("Progress: Adding workflow '{0}' to content type...", wf.Name); targetCT.WorkflowAssociations.Add(SPWorkflowAssociation.ImportFromXml(targetCT.ParentWeb.Site.RootWeb, wf.ExportToXml())); } targetCT.Update(); }
public static SPWorkflowAssociation CreateListWorkflowAssociation(this SPContentType contentType, SPWorkflowTemplate workflowTemplate, string assocName, SPList workflowTasksList, SPList workflowHistoryList, bool allowManual, bool autoStartCreate, bool autoStartChange, bool overwrite = false) { SPWorkflowAssociation workflowAssociation = contentType.CreateListWorkflowAssociation(workflowTemplate, assocName, workflowTasksList, workflowHistoryList, overwrite, assoc => { assoc.AllowManual = allowManual; assoc.AutoStartCreate = autoStartCreate; assoc.AutoStartChange = autoStartChange; }); return(workflowAssociation); }
private void GetAssociationInfo() { Guid associationTemplateId = new Guid(Request.Params["TemplateID"]); associationTemplate = list.WorkflowAssociations[associationTemplateId]; if (associationTemplate == null) { SPContentTypeId contentTypeId = (SPContentTypeId)listItem["ContentTypeId"]; SPContentType contentType = list.ContentTypes[contentTypeId]; associationTemplate = contentType.WorkflowAssociations[associationTemplateId]; } if (associationTemplate == null) throw new SPException("The requested workflow could not be found."); baseTemplate = Web.WorkflowTemplates[associationTemplate.BaseId]; workflowName = associationTemplate.Name; string m_formData = (string)associationTemplate.AssociationData; }
private void PopulateFormFields(SPWorkflowAssociation existingAssociation) { // Optionally, add code here to pre-populate your form fields. }
private void FetchAssociationInfo() { SPWorkflowAssociationCollection wfAccociationCollection; baseTemplate = Web.WorkflowTemplates[new Guid(Request.Params["WorkflowDefinition"])]; associationTemplate = null; if (contentType != null) { // Associating with a content type. wfAccociationCollection = contentType.WorkflowAssociations; hlReturn.Text = contentType.Name; hlReturn.NavigateUrl = "ManageContentType.aspx" + requestQueryString; } else { list.CheckPermissions(SPBasePermissions.ManageLists); wfAccociationCollection = list.WorkflowAssociations; hlReturn.Text = list.Title; hlReturn.NavigateUrl = list.DefaultViewUrl; } if (wfAccociationCollection == null || wfAccociationCollection.Count < 0) { throw new SPException("No Associations Found"); } workflowOptions.autoStartCreate = (Request.Params["AutoStartCreate"] == "ON"); workflowOptions.autoStartChange = (Request.Params["AutoStartChange"] == "ON"); workflowOptions.allowManual = (Request.Params["AllowManual"] == "ON"); workflowOptions.lockItem = (Request.Params["LockItem"] == "ON"); workflowOptions.setDefault = (Request.Params["SetDefault"] == "ON"); workflowOptions.updateLists = (Request.Params["UpdateLists"] == "TRUE"); string associationGuid = Request.Params["GuidAssoc"]; if (associationGuid != string.Empty) { associationTemplate = wfAccociationCollection[new Guid(associationGuid)]; } SPWorkflowAssociation checkForDuplicateTemplate = wfAccociationCollection.GetAssociationByName(workflowName, Web.Locale); if (checkForDuplicateTemplate != null && (associationTemplate == null || associationTemplate.Id != checkForDuplicateTemplate.Id)) { throw new SPException("Duplicate workflow name is detected."); } }
public void BtnOK_Click(object sender, EventArgs e) { SPList taskList = null; SPList historyList = null; if (!IsValid) return; if (!useContentTypeTemplate) { // If the user requested a new task list, create it. if (workflowOptions.taskListId == Guid.Empty) { string description = string.Format("Task list for the {0} workflow.", workflowName); workflowOptions.taskListId = Web.Lists.Add(workflowOptions.taskListName, description, SPListTemplateType.Tasks); } // If the user requested a new history list, create it. if (workflowOptions.historyListId == Guid.Empty) { string description = string.Format("History list for the {0} workflow.", workflowName); workflowOptions.historyListId = Web.Lists.Add(workflowOptions.historyListName, description, SPListTemplateType.WorkflowHistory); } taskList = Web.Lists[workflowOptions.taskListId]; historyList = Web.Lists[workflowOptions.historyListId]; } // Perform association (if it does not already exist). bool isNewAssociation; if (associationTemplate == null) { isNewAssociation = true; if (!useContentTypeTemplate) associationTemplate = SPWorkflowAssociation.CreateListAssociation(baseTemplate, workflowName, taskList, historyList); else { associationTemplate = SPWorkflowAssociation.CreateWebContentTypeAssociation(baseTemplate, workflowName, workflowOptions.taskListName, workflowOptions.historyListName); } } else // Modify existing template. { isNewAssociation = false; associationTemplate.Name = workflowName; associationTemplate.SetTaskList(taskList); associationTemplate.SetHistoryList(historyList); } // Set up startup parameters in the template. associationTemplate.Name = workflowName; associationTemplate.LockItem = workflowOptions.lockItem; associationTemplate.AutoStartCreate = workflowOptions.autoStartCreate; associationTemplate.AutoStartChange = workflowOptions.autoStartChange; associationTemplate.AllowManual = workflowOptions.allowManual; if (associationTemplate.AllowManual) { SPBasePermissions newPerms = SPBasePermissions.EmptyMask; if (Request.Params["ManualPermEditItemRequired"] == "ON") newPerms |= SPBasePermissions.EditListItems; if (Request.Params["ManualPermManageListRequired"] == "ON") newPerms |= SPBasePermissions.ManageLists; associationTemplate.PermissionsManual = newPerms; } // Place data from form into the association template. associationTemplate.AssociationData = base.SerializePagetoXml(FormType.Association); // If this is a content type association, add the template to the content type. if (contentType != null) { if (isNewAssociation) contentType.WorkflowAssociations.Add(associationTemplate); else contentType.WorkflowAssociations.Update(associationTemplate); if (workflowOptions.updateLists) contentType.UpdateWorkflowAssociationsOnChildren(false); } else // Else, if this is a list association. { if (isNewAssociation) list.WorkflowAssociations.Add(associationTemplate); else list.WorkflowAssociations.Update(associationTemplate); if (associationTemplate.AllowManual && list.EnableMinorVersions) { // If this WF was selected to be the content approval WF // (m_setDefault = true, see association page) then enable content // Approval for the list. if (list.DefaultContentApprovalWorkflowId != associationTemplate.Id && workflowOptions.setDefault) { if (!list.EnableModeration) list.EnableModeration = true; list.DefaultContentApprovalWorkflowId = associationTemplate.Id; list.Update(); } else if (list.DefaultContentApprovalWorkflowId == associationTemplate.Id && !workflowOptions.setDefault) { // Reset the DefaultContentApprovalWorkflowId list.DefaultContentApprovalWorkflowId = Guid.Empty; list.Update(); } } } SPUtility.Redirect("WrkSetng.aspx", SPRedirectFlags.RelativeToLayoutsPage, HttpContext.Current, requestQueryString); }
private void PopulateFormFields(SPWorkflowAssociation existingAssociation) { // Optionally, add code here to pre-populate your form fields. if (existingAssociation != null && !string.IsNullOrEmpty(existingAssociation.AssociationData)) { BCWorkflowAssociationData data = SerializationHelper.DeserializeFromXml<BCWorkflowAssociationData>(existingAssociation.AssociationData); BindPeoplePicker(ppGS, new List<string>() { data.GeneralSupervisor }); txtTitle.Text = data.TaskTitle; txtMessage.Text = data.Message; } }
private void PopulateAssociationParams(SPWorkflowAssociation association) { association.Name = this.associationParams.AssociationName; association.AutoStartCreate = this.associationParams.AutoStartCreate; association.AutoStartChange = this.associationParams.AutoStartChange; association.AllowManual = this.associationParams.AllowManual; association.LockItem = this.associationParams.LockItem; association.ContentTypePushDown = this.associationParams.ContentTypePushDown; if (association.AllowManual) { association.PermissionsManual = SPBasePermissions.EmptyMask; if (this.associationParams.RequireManagedListPermisions) { association.PermissionsManual |= (this.associationParams.TargetListGuid != Guid.Empty) ? SPBasePermissions.ManageLists : SPBasePermissions.ManageWeb; } } association.AssociationData = GetAssociationData(); }
private void PopulateFormFields(SPWorkflowAssociation existingAssociation) { // Optionally, add code here to pre-populate your form fields. if (existingAssociation != null && !string.IsNullOrEmpty(existingAssociation.AssociationData)) { ApprovalUC.AssociationForm = SerializationHelper.DeserializeFromXml<ApprovalWFAssociationData>(existingAssociation.AssociationData); } }
private void MapProperties(WorkflowAssociationDefinition definition, SPWorkflowAssociation association) { if (!string.IsNullOrEmpty(definition.Description)) association.Description = definition.Description; if (!string.IsNullOrEmpty(definition.AssociationData)) association.AssociationData = definition.AssociationData; if (definition.AllowManual.HasValue) association.AllowManual = definition.AllowManual.Value; if (definition.AutoStartChange.HasValue) association.AutoStartChange = definition.AutoStartChange.Value; if (definition.AutoStartCreate.HasValue) association.AutoStartCreate = definition.AutoStartCreate.Value; if (definition.Enabled.HasValue) association.Enabled = definition.Enabled.Value; }
private void SetDefaultContentApprovalWorkflow(SPList targetList, SPWorkflowAssociation association) { if (targetList.EnableMinorVersions) { if (targetList.DefaultContentApprovalWorkflowId != association.Id && this.associationParams.SetDefaultApprovalWorkflow) { if (!targetList.EnableModeration) { targetList.EnableModeration = true; targetList.DraftVersionVisibility = DraftVisibilityType.Approver; } targetList.DefaultContentApprovalWorkflowId = association.Id; targetList.Update(); } else if (targetList.DefaultContentApprovalWorkflowId == association.Id && !this.associationParams.SetDefaultApprovalWorkflow) { targetList.DefaultContentApprovalWorkflowId = Guid.Empty; targetList.Update(); } } }