{"id":148,"date":"2010-09-07T19:13:31","date_gmt":"2010-09-07T19:13:31","guid":{"rendered":"http:\/\/collaboriscom.wpengine.com\/?p=148"},"modified":"2022-04-12T08:13:41","modified_gmt":"2022-04-12T08:13:41","slug":"how-to-start-the-default-approval-workflow-programmatically","status":"publish","type":"post","link":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/","title":{"rendered":"How to start the default approval workflow programmatically"},"content":{"rendered":"<p>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\u00a0<a href=\"http:\/\/blogs.technet.com\/b\/victorbutuza\/archive\/2009\/03\/14\/workflows-do-not-start.aspx\">this blog post<\/a>\u00a0for more information).<\/p>\n<p>The main requirements I needed to solve were:<\/p>\n<p>1) Determine what is the default content approval workflow associated with the Pages library.<\/p>\n<p>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.<\/p>\n<p>3) Pass the default association data to the workflow (without asking the user for more information).<\/p>\n<p>Here is the code for the solution I found:<br \/>\n<script src=\"https:\/\/gist.github.com\/ClbMarkJones\/ef8dfed711d9d52ee7ab18bd3d17f815.js\"><\/script><\/p>\n<p>I hope you find this code sample useful.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2106,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"no","_lmt_disable":"","footnotes":""},"categories":[28],"tags":[],"class_list":["post-148","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sharepoint"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v26.6) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Starting an approval workflow automatically - Collaboris<\/title>\n<meta name=\"description\" content=\"This post contains the code samples needed to start the default approval workflow programmatically\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to start the default approval workflow programmatically\" \/>\n<meta property=\"og:description\" content=\"This post contains the code samples needed to start the default approval workflow programmatically\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/\" \/>\n<meta property=\"og:site_name\" content=\"Collaboris\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Collaboris\/\" \/>\n<meta property=\"article:published_time\" content=\"2010-09-07T19:13:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-12T08:13:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Hugo Esperanca\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Collaboris\" \/>\n<meta name=\"twitter:site\" content=\"@Collaboris\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hugo Esperanca\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/\"},\"author\":{\"name\":\"Hugo Esperanca\",\"@id\":\"https:\/\/www.collaboris.com\/#\/schema\/person\/f870363212c9f9d0c02bcd8b0bb84f81\"},\"headline\":\"How to start the default approval workflow programmatically\",\"datePublished\":\"2010-09-07T19:13:31+00:00\",\"dateModified\":\"2022-04-12T08:13:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/\"},\"wordCount\":179,\"publisher\":{\"@id\":\"https:\/\/www.collaboris.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png\",\"articleSection\":[\"SharePoint\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/\",\"url\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/\",\"name\":\"Starting an approval workflow automatically - Collaboris\",\"isPartOf\":{\"@id\":\"https:\/\/www.collaboris.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png\",\"datePublished\":\"2010-09-07T19:13:31+00:00\",\"dateModified\":\"2022-04-12T08:13:41+00:00\",\"description\":\"This post contains the code samples needed to start the default approval workflow programmatically\",\"breadcrumb\":{\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#primaryimage\",\"url\":\"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png\",\"contentUrl\":\"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png\",\"width\":820,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.collaboris.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to start the default approval workflow programmatically\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.collaboris.com\/#website\",\"url\":\"https:\/\/www.collaboris.com\/\",\"name\":\"Collaboris\",\"description\":\"We make compliance simple\",\"publisher\":{\"@id\":\"https:\/\/www.collaboris.com\/#organization\"},\"alternateName\":\"DocRead\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.collaboris.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.collaboris.com\/#organization\",\"name\":\"Collaboris\",\"alternateName\":\"DocRead\",\"url\":\"https:\/\/www.collaboris.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.collaboris.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.collaboris.com\/wp-content\/uploads\/2021\/05\/collaboris_logo_small.png\",\"contentUrl\":\"https:\/\/www.collaboris.com\/wp-content\/uploads\/2021\/05\/collaboris_logo_small.png\",\"width\":150,\"height\":40,\"caption\":\"Collaboris\"},\"image\":{\"@id\":\"https:\/\/www.collaboris.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Collaboris\/\",\"https:\/\/x.com\/Collaboris\",\"https:\/\/www.linkedin.com\/company\/collaboris\"],\"description\":\"Collaboris is a Software company that created a policy management tool called DocRead.\",\"email\":\"info@collaboris.com\",\"telephone\":\"02079935140\",\"legalName\":\"Collaboris Ltd\",\"foundingDate\":\"2007-12-03\",\"vatID\":\"GB928895360\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1\",\"maxValue\":\"10\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.collaboris.com\/#\/schema\/person\/f870363212c9f9d0c02bcd8b0bb84f81\",\"name\":\"Hugo Esperanca\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.collaboris.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a476a96fe969976019d0f40d6b8910365b29f8d1fa4e352ddd61afe518a981b8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a476a96fe969976019d0f40d6b8910365b29f8d1fa4e352ddd61afe518a981b8?s=96&d=mm&r=g\",\"caption\":\"Hugo Esperanca\"},\"url\":\"https:\/\/www.collaboris.com\/author\/hugo\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Starting an approval workflow automatically - Collaboris","description":"This post contains the code samples needed to start the default approval workflow programmatically","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/","og_locale":"en_GB","og_type":"article","og_title":"How to start the default approval workflow programmatically","og_description":"This post contains the code samples needed to start the default approval workflow programmatically","og_url":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/","og_site_name":"Collaboris","article_publisher":"https:\/\/www.facebook.com\/Collaboris\/","article_published_time":"2010-09-07T19:13:31+00:00","article_modified_time":"2022-04-12T08:13:41+00:00","og_image":[{"width":820,"height":300,"url":"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png","type":"image\/png"}],"author":"Hugo Esperanca","twitter_card":"summary_large_image","twitter_creator":"@Collaboris","twitter_site":"@Collaboris","twitter_misc":{"Written by":"Hugo Esperanca","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#article","isPartOf":{"@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/"},"author":{"name":"Hugo Esperanca","@id":"https:\/\/www.collaboris.com\/#\/schema\/person\/f870363212c9f9d0c02bcd8b0bb84f81"},"headline":"How to start the default approval workflow programmatically","datePublished":"2010-09-07T19:13:31+00:00","dateModified":"2022-04-12T08:13:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/"},"wordCount":179,"publisher":{"@id":"https:\/\/www.collaboris.com\/#organization"},"image":{"@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#primaryimage"},"thumbnailUrl":"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png","articleSection":["SharePoint"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/","url":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/","name":"Starting an approval workflow automatically - Collaboris","isPartOf":{"@id":"https:\/\/www.collaboris.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#primaryimage"},"image":{"@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#primaryimage"},"thumbnailUrl":"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png","datePublished":"2010-09-07T19:13:31+00:00","dateModified":"2022-04-12T08:13:41+00:00","description":"This post contains the code samples needed to start the default approval workflow programmatically","breadcrumb":{"@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#primaryimage","url":"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png","contentUrl":"https:\/\/www.collaboris.com\/wp-content\/uploads\/2016\/07\/blue_820x300_sharepoint_img.png","width":820,"height":300},{"@type":"BreadcrumbList","@id":"https:\/\/www.collaboris.com\/how-to-start-the-default-approval-workflow-programmatically\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.collaboris.com\/"},{"@type":"ListItem","position":2,"name":"How to start the default approval workflow programmatically"}]},{"@type":"WebSite","@id":"https:\/\/www.collaboris.com\/#website","url":"https:\/\/www.collaboris.com\/","name":"Collaboris","description":"We make compliance simple","publisher":{"@id":"https:\/\/www.collaboris.com\/#organization"},"alternateName":"DocRead","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.collaboris.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/www.collaboris.com\/#organization","name":"Collaboris","alternateName":"DocRead","url":"https:\/\/www.collaboris.com\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.collaboris.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.collaboris.com\/wp-content\/uploads\/2021\/05\/collaboris_logo_small.png","contentUrl":"https:\/\/www.collaboris.com\/wp-content\/uploads\/2021\/05\/collaboris_logo_small.png","width":150,"height":40,"caption":"Collaboris"},"image":{"@id":"https:\/\/www.collaboris.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Collaboris\/","https:\/\/x.com\/Collaboris","https:\/\/www.linkedin.com\/company\/collaboris"],"description":"Collaboris is a Software company that created a policy management tool called DocRead.","email":"info@collaboris.com","telephone":"02079935140","legalName":"Collaboris Ltd","foundingDate":"2007-12-03","vatID":"GB928895360","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1","maxValue":"10"}},{"@type":"Person","@id":"https:\/\/www.collaboris.com\/#\/schema\/person\/f870363212c9f9d0c02bcd8b0bb84f81","name":"Hugo Esperanca","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.collaboris.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a476a96fe969976019d0f40d6b8910365b29f8d1fa4e352ddd61afe518a981b8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a476a96fe969976019d0f40d6b8910365b29f8d1fa4e352ddd61afe518a981b8?s=96&d=mm&r=g","caption":"Hugo Esperanca"},"url":"https:\/\/www.collaboris.com\/author\/hugo\/"}]}},"modified_by":"Helen Jones","_links":{"self":[{"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":5,"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":1371943,"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/posts\/148\/revisions\/1371943"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/media\/2106"}],"wp:attachment":[{"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.collaboris.com\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}