如何使用客户端对象模型关联SharePoint工作流程?

3

如何在SharePoint对象模型(SP 2010)中将工作流与给定列表关联?

我已经能够关联工作流,但配置设置没有保存回SharePoint。换句话说,基本的WorkflowAssociationCreationInformation被保存回了SharePoint,但使用WorkflowAssociation进行的任何进一步配置设置都没有保存。

以下是我正在使用的代码:

var context = new ClientContext( url );
Web site = context.Web;

var query = context.LoadQuery( site.WorkflowTemplates.Where( x => x.Name == "My Template Name" ) );
context.ExecuteQuery();
WorkflowTemplate wfTemplate = query.Single();

var wfc = new WorkflowAssociationCreationInformation();
wfc.HistoryList = site.Lists.GetByTitle( "Workflow History" );
wfc.Name = "My Workflow Name";
wfc.TaskList = site.Lists.GetByTitle( "Tasks" );
wfc.Template = wfTemplate;

List list = site.Lists.GetByTitle( "List Name" );

WorkflowAssociation wf = list.WorkflowAssociations.Add( wfc );
wf.AllowManual = false; // is never updated
wf.AutoStartChange = false; // is never updated
wf.AutoStartCreate = true; // is never updated
wf.Enabled = true; // is never updated
string assocData = GetAssociationXml(); // internal method
wf.AssociationData = assocData; // is never updated

context.Load( wf );
context.ExecuteQuery(); // does not update the SP workflow with any of the new wf settings

在设置完您的配置项后,难道不需要列出.WorkflowAssociations.Update(wf)吗? - vinny
1
@vinny,确实是这样。发帖后一个小时就想到了,但忘记更新问题了。非常好的发现!请继续添加答案,我会接受它的。 - Metro Smurf
2个回答

1

list.WorkflowAssociations.Update(wf) 在设置配置项后,将会更新WorkflowAssociation上的配置项。

Note: The translated text is in simplified Chinese.

你确定 list.WorkflowAssociations.Update() 是一个方法吗? 我只看到单个关联的更新方法,而且在我的情况下似乎不起作用。 - user3362735
是的 - 它是列表workflowassociationcollection的一个method - vinny
这不是使用客户端对象模型,所以这不起作用。将其标记为答案有点误导,特别是因为最接近的客户端等效项似乎无法工作。 - user3362735

0
    ...
    wf.AssociationData = assocData;
    wf.Update();//Update association config
    list.Update();//Update the list

    context.Load(wf);
    context.ExecuteQuery();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接