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
4

2 回答 2

1

list.WorkflowAssociations.Update(wf)设置您的配置项后将更新您的配置项WorkflowAssociation

于 2011-02-16T17:09:46.700 回答
0
    ...
    wf.AssociationData = assocData;
    wf.Update();//Update association config
    list.Update();//Update the list

    context.Load(wf);
    context.ExecuteQuery();
于 2013-07-22T14:37:35.617 回答