Sitecore的:分配工作流程,一个项目编程 [英] Sitecore: Assign workflow to an item programmatically
问题描述
我已经配置的工作流,开始以草稿状态如常。我已经配置了模板的标准值的工作流程。它工作在内容编辑器完美。
(当我创建使用内容编辑器中的项目,一旦我创建的项目,工作流被分配到该项目,它的状态变为草案)。
但是,当我在上面的模板下编程创建一个项目它不分配工作流程。
我应该怎么做分配的工作流程?请分享任何代码样本,如果你有。
感谢。
<预类=郎-CS prettyprint-覆盖 >
Sitecore.Data.Items.TemplateItem模板= this.MasterDatabase.GetItem(/ Sitecore的/模板/用户自定义/样品类型);
Sitecore.Data.Items.Item父= this.MasterDatabase.GetItem(parentId的);
Sitecore.Data.Items.Item的newitem;
//创建新的项目和检索
的newitem = template.CreateItemFrom(sampleName,父母);
newItem.Editing.BeginEdit();
newItem.Name = StringFormatter.CreateItemNameFromID(this.newItem);
newItem.Fields [标题] =价值样品名称
newItem.Editing.EndEdit();
解决和标准领域的问题,
newItem.Editing.BeginEdit();
newItem.Fields [__工作流程]值={4D1F00EF-CA5D-4F36-A51E-E77E2BAE4A24}。 //设置工作流程
newItem.Fields [__工作流程状态]值={7F39DF46-B4B9-4D08-A0D4-32DE6FD643D1}。 //设置工作流状态为未发布的。
newClassified.Editing.EndEdit();
I have configured a workflow, starts with "Draft" state as usual. And I have configured the workflow for standard values of the template. It works perfect in Content editor. (When I create an item using the content editor, once I create the item, Workflow gets assigned to the item and it's state becomes "Draft".)
But when I create an item programmatically under the above template it does not assign the workflow. What should I do to assign workflow? Please share any code samples if you have.
Thanks.
Sitecore.Data.Items.TemplateItem template = this.MasterDatabase.GetItem("/sitecore/templates/user defined/sample types");
Sitecore.Data.Items.Item parent = this.MasterDatabase.GetItem(parentId);
Sitecore.Data.Items.Item newItem;
// Create new item and retrieve it
newItem = template.CreateItemFrom("sampleName", parent);
newItem.Editing.BeginEdit();
newItem.Name = StringFormatter.CreateItemNameFromID(this.newItem);
newItem.Fields["Title"].Value = "Sample Title"
newItem.Editing.EndEdit();
Solved the issue with Standard Fields,
newItem.Editing.BeginEdit();
newItem.Fields["__Workflow"].Value = "{4D1F00EF-CA5D-4F36-A51E-E77E2BAE4A24}"; //Set workflow
newItem.Fields["__Workflow state"].Value = "{7F39DF46-B4B9-4D08-A0D4-32DE6FD643D1}"; //Set workflow state to Unposted.
newClassified.Editing.EndEdit();
这篇关于Sitecore的:分配工作流程,一个项目编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!