質問

i am associating a custom workflow to a library using csom. How do i select checkbox : Start this workflow to approve publishing a major version of an item using csom.

役に立ちましたか?

解決 2

Thank you for the comments i have got the solution too. below is my code

clientContext.Load(web.WorkflowTemplates);
            clientContext.Load(web.Lists);
            clientContext.ExecuteQuery();
            WorkflowTemplate wfTemplate = web.WorkflowTemplates.GetByName(workFlowName);
            var wfc = new WorkflowAssociationCreationInformation();
            wfc.HistoryList = web.Lists.GetByTitle("Approval Workflow History");
            wfc.Name = "Test Approval Workflow";
            wfc.TaskList = web.Lists.GetByTitle("Approval Tasks");
            wfc.Template = wfTemplate;

        WorkflowAssociation wf = list.WorkflowAssociations.Add(wfc);
        wf.AllowManual = false; 
        wf.AutoStartChange = false; 
        wf.AutoStartCreate = false; 
        wf.Enabled = true;            
        wf.Update();
        clientContext.Load(wf);

        if (null != wfTemplate)
        {
            clientContext.Load(wfTemplate);
            clientContext.ExecuteQuery();
            list.EnableModeration = true;
            list.EnableMinorVersions = true;
            list.DefaultContentApprovalWorkflowId = wf.Id;               

            list.Update();
            clientContext.ExecuteQuery();` 

他のヒント

Because you are using a custom workflow, I assume you have an Start Approval Process action in your workflow. In this scenario, you need to do two things:

  • In the workflow just before the "Start Approval Process" action set the EnableContentApproval workflow variable to Yes. Note that this workflow variable is automatically created when you add the "Start Approval Process" action to your workflow.
    enter image description here

  • Then using CSOM (or PowerShell) set the DefaultContentApprovalWorkflowId property of the SPList class to the id of the workflow association.
    Since you are using CSOM to associate the workflow with a library, then your code should give you back an SPWorkflowAssociation object which contains the id of the workflow association. You can also get the workflow id by looping through the workflow associations of your list (see SPList.WorkflowAssociations) and checking if the workflow name matches one of the associations.

Notes

The workflow association id changes every single time you re-associate the workflow with the library, therefore you have to also update the DefaultContentApprovalWorkflowId property of the library.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top