locked
The default content approval workflow for a list must be a workflow that is already associated with the list RRS feed

  • Question

  •  

    I have created a custom workflow and trying to set it as Defualt Content Approval workflow. When I try to set this value, I get the below error.

    "The default content approval workflow for a list must be a workflow that is already associated with the list."

    Below is the code.

                SPSite site = new SPSite("<SDite URL>");

                SPWeb web = site.Rootweb;

                SPList pages = web.Lists["Pages"];

                // Require content approval

                pages.EnableModeration = true;

                // Create major and minor versions

                pages.EnableVersioning = true;

                pages.EnableMinorVersions = true;

                // Who should see draft items

                pages.DraftVersionVisibility = DraftVisibilityType.Author;

                // Require documents to be checked out before they can be edited

                pages.ForceCheckout = true;

                pages.Update();

                foreach (SPWorkflowTemplate workflowTemplate in web.WorkflowTemplates)

                {

                    if (workflowTemplate.Name == "<Custom workflow name>")

                    {

                        SPList taskList=web.Lists["tasks"];

                        SPList historyList=web.Lists["Workflow History"];

    SPWorkflowAssociation workflowAssociation =    SPWorkflowAssociation.CreateListAssociation(workflowTemplate, "kkk", taskList, historyList);

                        pages.DefaultContentApprovalWorkflowId = workflowAssociation.Id;

                        pages.Update();

                    }

    Any hints/reference links would be a great help.

    Thanks!

    Ravi


    Ravi

    Tuesday, April 3, 2012 3:38 PM

All replies