3

Can anyone help me on steps to associate the default approval workflow to a SharePoint Library through CSOM ?

Update: When i call ennumeratedefinitions(true) on the workflowservices manager, it only gives the collection of SP13 Workflows. The 2010 Approval WF is not getting intialize.

3

2 Answers 2

2

Basically you need to set EnableModeration = true.

var ctx = new SP.ClientContext(siteUrl);
var web = ctx.get_web();
var list = web.get_lists().getByTitle('Your list');
list.set_enableModeration(true);
list.set_enableMinorVersions(true);
list.set_defaultContentApprovalWorkflowId("guid");
list.update()
2
  • i want the OOB Approval workflow to be added to the document library.
    – Arvi
    Commented Aug 3, 2015 at 14:08
  • Yes this will actually do that.
    – Taran Goel
    Commented Aug 3, 2015 at 14:10
0

To add OOTB 2010 workflow to SharePoint List by CSOM . Get the List of SharePoint 2010 Workflow Templates by using the below method

webObj.WorkflowTemplates

I needed the Approval workflow. So i get it by its name after finding out in previous method.

$wfApprovalWFTemplate = webObj.WorkflowTemplates.GetByName("Approval - SharePoint 2010")

Note:

When getting the list of workflows using the Workflow Service Manager Class will return only all those WF's created by SP2013 . i.e Through Workflow Manager.

Create a Workflow Association info

$wfassociationInfo = New-Object Microsoft.SharePoint.Client.Workflow.WorkflowAssociationCreationInformation;
$wfassociationInfo.Template = $wfApprovalWFTemplate;
$wfassociationInfo.Name = "Document Approval"
$wfassociationInfo.TaskList ="#Task List to Assign"
$wfassociationInfo.HistoryList = "#WF History List to Assign"

Associate to the Document Library where you want the approval WF to be added .

Write-Host "Create a new Workflow Associationg with the Neccesary information."
$wf = $listWFToAdd.WorkflowAssociations.Add($wfassociationInfo)
$wf.AutoStartChange = $true
$wf.AutoStartCreate = $true
$wf.AssociationData = $customAssociationData //XML data to store WF Options--You can loop through and get this value from existing workflows to get the structure and settings done.
$wf.Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.