SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to programmatically configure the out of the box Approval workflow on a document library using the following code:

SPWorkflowTemplate workflowTemplate = web.WorkflowTemplates.GetTemplateByName(workflowName,
SPWorkflowAssociation workflowAssociation =
    SPWorkflowAssociation.CreateListAssociation(workflowTemplate, workflowAssocName, workflowWorkList, workflowLogList);

workflowAssociation.AllowAsyncManualStart = false;
workflowAssociation.AllowManual = false;
var associationDataXml = XElement.Parse(workflowAssociation.AssociationData);
workflowAssociation.AssociationData = GetAssociationData(web, associationDataXml);

workflowAssociation.Enabled = true;

documentLibrary.DefaultContentApprovalWorkflowId = workflowAssociation.Id;

I believe that the GetAssociationData() method returns the correct XML. I have compared the output from the function with the XML set by configuring the workflow manually (using powershell/sharepoint manager). The XML generated GetAssociationData() is actually saved in AssociationData and I can access it after the code have run, there are no exceptions thrown in the code above.

Example of XML:

<!-- generated xml, comment added manually -->
<dfs:myFields xmlns:xsd="" xmlns:dms="" xmlns:dfs="" xmlns:q="" xmlns:d="" xmlns:ma="" xmlns:pc="" xmlns:xsi="">
                    <d:Stage xsi:nil="true" />
            <d:NotificationMessage />
            <d:DueDateforAllTasks xsi:nil="true" />
            <d:DurationforSerialTasks xsi:nil="true" />
            <d:CC />


My problem is that SP-GROUP does not show up in the gui when starting the workflow. Any ideas? Do I have to update the workflow in some way after altering AssociationData? The groups I'm using exists and are working.

Image summary:

share|improve this question

You need to update the workflow:

// Update Workflow Association Data
wfAssociation.AssociationData = data;
wfAssociation.Enabled = true;

// Update Workflow Association

I wrote a blogpost about this topic with a possible solution, maybe it could be handy:

share|improve this answer
I found the error, the code was working but I had a tiny error in the XML. That's those hours wasted.. – Vegard Feb 10 '12 at 14:04
To avoid such errors you can set up approvers through UI and then grab generated xml using sharepoint manager. – Kai Feb 10 '12 at 19:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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