How to start the default approval workflow programmatically

How to start the default approval workflow programmatically

Today I was trying to find a way to programmatically create a publishing page and start the default approval workflow attached to the pages library. The reason that I had to programmatically start the workflow (instead of relying on SharePoint to automatically start it for me) was because my code was running under the system account (in this case under a WCF web service IIS process) and, since SP1, SharePoint will not automatically start a workflow if the list item is being changed by the system account (see this blog post for more information).

The main requirements I needed to solve were:

1) Determine what is the default content approval workflow associated with the Pages library.

2) Start the approval workflow when a Page is programmatically added to the Publishing Pages list but only if approval is enabled on the list.

3) Pass the default association data to the workflow (without asking the user for more information).

Here is the code for the solution I found:

I hope you find this code sample useful.

Similar Posts

  • |

    Using metadata to classify policies

    Using metadata to classify policiesIn this post, we will to find out how SharePoint metadata can be used to tag and classify a policy to make it more discoverable.Along with search, managed metadata is a service in SharePoint that operates at the organization level to allow for comprehensive classification and tagging of enterprise content. As…

  • | |

    SharePoint Groups vs AD Groups vs Global Audiences

    SharePoint Groups vs AD Groups vs Global AudiencesIf you’d like to know whether to use SharePoint Groups or SharePoint Audiences to manage users, then look no further! This post will help you decipher what to use and when. I also want to include a little discussion on SharePoint Audiences as I believe they are a…

  • | |

    How to migrate DocRead from SharePoint 2016 to SharePoint 2019

    How to Migrate DocRead from SharePoint 2016 to SharePoint 2019Note: The information in this post relates to DocRead for on-premises SharePoint only. If you are considering migrating your SharePoint 2016 Farm to SharePoint 2019 then please read through this article for steps on how to achieve this. Before proceeding, it’s important that you read ‘migrating between editions‘…

  • What are your favourite SharePoint 2013 Features?

    Private: What are your favourite SharePoint 2013 Features?SharePoint 2013 has shipped and it’s now main stream. We’d love to hear what your favourite 2013 features are, so please add them! Also vote up the killer ones and why not embed the list to see if we can make it one awesome resource! Favourite SharePoint 2013 features?

  • |

    Creating a Policy Approval Workflow with Power Automate

    Policy Approval WorkflowAutomated policy approval workflows offer several benefits that can significantly enhance the efficiency and accuracy of policy creation within an organization. Here are some of the key advantages:Increased Efficiency: Automation speeds up the document approval process by eliminating manual steps. This results in quicker turnaround times for document approvals.Reduced Errors: Automated workflows minimize…