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

发布于 2024-10-17 16:08:33 字数 1249 浏览 3 评论 0原文

使用 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

Using the SharePoint Object Model (SP 2010), how can you associate a workflow with a given list?

I've been able to associate a workflow, but the configuration settings do not get saved back to SharePoint. In other words, the basicWorkflowAssociationCreationInformation is saved back to SharePoint, but any further configuration settings using the WorkflowAssociation are not saved.

Here is the code I've been working on:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

从此见与不见 2024-10-24 16:08:33

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

list.WorkflowAssociations.Update(wf) after setting your config items will update the config items on your WorkflowAssociation.

满栀 2024-10-24 16:08:33
    ...
    wf.AssociationData = assocData;
    wf.Update();//Update association config
    list.Update();//Update the list

    context.Load(wf);
    context.ExecuteQuery();
    ...
    wf.AssociationData = assocData;
    wf.Update();//Update association config
    list.Update();//Update the list

    context.Load(wf);
    context.ExecuteQuery();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文