开发者

How to associate a SharePoint workflow using the Client Object Model?

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 WorkflowAssociationCre开发者_StackOverflow社区ationInformation();
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


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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜