{"componentChunkName":"component---src-templates-post-template-post-template-tsx","path":"/posts/sitecore-workflows-custom-workflow-actions/","result":{"data":{"markdownRemark":{"id":"08da780e-b7f0-58af-bc0a-6e2198640beb","html":"<p>This article will cover how we can create a custom workflow action for Workflows with Sitecore.</p>\n<h2 id=\"ootb-submit-actions\" style=\"position:relative;\"><a href=\"#ootb-submit-actions\" aria-label=\"ootb submit actions permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>OOTB Submit Actions</h2>\n<p>Sitecore offers a few OOTB Submit Actions which can be used as per your requirements.</p>\n<ol>\n<li><strong>Auto Submit Action</strong>\nThis action can be utilized to automatically submit an item if it is saved by a user from a certain role.\nIt accepts the Type (which will remain the same), Next State and the Role Name.\nTemplate Path: <em>/sitecore/templates/System/Workflow/Auto Submit Action</em></li>\n<li><strong>Validation Action</strong>\nIt can be used to refuse a change in state if the item has validation errors.\nYou can mention the maximum allowed result - Warning, Error etc. and the messages to be shown in case of errors.\nTemplate Path: <em>/sitecore/templates/System/Workflow/Validation Action</em></li>\n<li><strong>Auto Publish</strong>\nAuto Publish, as the name suggests can be used to trigger a publish on the item if it moves to a certain final state.\nIt accepts parameters such as deep (To publish with subitems) and smart (For a smart publish).\nTemplate Path: <em>/sitecore/templates/System/Workflow/Action</em>\nType: <em>Sitecore.Workflows.Simple.PublishAction, Sitecore.Kernel</em>\nParameters: deep=1&#x26;smart=1 (Set to 0 if false, or exclude it).</li>\n<li><strong>Email Action</strong>\nIt can be used to send an email to mentioned emails to inform a state change.\nTemplate Path: /sitecore/templates/System/Workflow/Email action</li>\n</ol>\n<h2 id=\"creating-your-own-custom-workflow-action\" style=\"position:relative;\"><a href=\"#creating-your-own-custom-workflow-action\" aria-label=\"creating your own custom workflow action permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Creating your own custom workflow action</h2>\n<p>There are 2 steps in creating your custom workflow action:</p>\n<ol>\n<li>Create a template with the fields that you need to be passed to the workflow action code. The <em>Type</em> field is a mandatory field.</li>\n<li>Create a class with a Process method accepting a parameter of type <strong>WorkflowPipelineArgs</strong>. The fully qualified name of this class will be populated in the Type field of the action item.</li>\n</ol>\n<p>The class will look like below:</p>\n<div class=\"gatsby-highlight\" data-language=\"csharp\"><pre class=\"language-csharp\"><code class=\"language-csharp\"><span class=\"token keyword\">using</span> <span class=\"token namespace\">Sitecore<span class=\"token punctuation\">.</span>Diagnostics</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">using</span> <span class=\"token namespace\">Sitecore<span class=\"token punctuation\">.</span>Workflows<span class=\"token punctuation\">.</span>Simple</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">using</span> <span class=\"token namespace\">System</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">using</span> <span class=\"token namespace\">Sitecore<span class=\"token punctuation\">.</span>Data<span class=\"token punctuation\">.</span>Items</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">namespace</span> <span class=\"token namespace\">Foundation<span class=\"token punctuation\">.</span>Workflow<span class=\"token punctuation\">.</span>Actions</span>\n<span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">public</span> <span class=\"token keyword\">class</span> <span class=\"token class-name\">CustomWorkflowAction</span>\n    <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">public</span> <span class=\"token return-type class-name\"><span class=\"token keyword\">void</span></span> <span class=\"token function\">Process</span><span class=\"token punctuation\">(</span><span class=\"token class-name\">WorkflowPipelineArgs</span> args<span class=\"token punctuation\">)</span>\n        <span class=\"token punctuation\">{</span>\n            <span class=\"token keyword\">try</span>\n            <span class=\"token punctuation\">{</span>\n                Assert<span class=\"token punctuation\">.</span><span class=\"token function\">ArgumentNotNull</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">,</span> <span class=\"token string\">\"args\"</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n                <span class=\"token class-name\">Item</span> dataItem <span class=\"token operator\">=</span> args<span class=\"token punctuation\">.</span>DataItem<span class=\"token punctuation\">;</span> <span class=\"token comment\">// This will be the page item</span>\n                <span class=\"token class-name\">ProcessorItem</span> processorItem <span class=\"token operator\">=</span> args<span class=\"token punctuation\">.</span>ProcessorItem<span class=\"token punctuation\">;</span>\n                <span class=\"token class-name\">Item</span> actionItem <span class=\"token operator\">=</span> processorItem<span class=\"token punctuation\">?.</span>InnerItem<span class=\"token punctuation\">;</span> <span class=\"token comment\">// This will be the action item itself</span>\n\t\t<span class=\"token class-name\"><span class=\"token keyword\">string</span></span> myValue <span class=\"token operator\">=</span> actionItem<span class=\"token punctuation\">[</span><span class=\"token string\">\"My Field Name\"</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">// Access the values from the action like this</span>\n\t\t<span class=\"token comment\">/*\n\t\t\tYour code goes here\n\t\t*/</span>\n            <span class=\"token punctuation\">}</span>\n            <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span><span class=\"token class-name\">Exception</span> ex<span class=\"token punctuation\">)</span>\n            <span class=\"token punctuation\">{</span>\n                Log<span class=\"token punctuation\">.</span><span class=\"token function\">Error</span><span class=\"token punctuation\">(</span>ex<span class=\"token punctuation\">.</span>Message<span class=\"token punctuation\">,</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span>\n\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>Now, you can add the action item under the workflow command on which you need it to be triggered. Remember to add the value for the Type field as the fully qualified name of the class.</p>\n<p><strong><em>Happy Sitecoring!</em></strong></p>","fields":{"slug":"/posts/2023-10-13-sitecore-workflows-custom-workflow-actions//posts/sitecore-workflows-custom-workflow-actions","tagSlugs":["/tag/sitecore/","/tag/workflows/"]},"frontmatter":{"date":"2023-10-13T16:33:25.581Z","description":"This article will cover how we can create a custom workflow action for Workflows with Sitecore.","tags":["Sitecore","Workflows"],"title":"Sitecore Workflows - Custom Workflow Actions","socialImage":{"publicURL":"/static/75be7c1e5ed43564cce58f6606e87463/vinayjadav_profilepicture.png"}}}},"pageContext":{"slug":"/posts/2023-10-13-sitecore-workflows-custom-workflow-actions//posts/sitecore-workflows-custom-workflow-actions"}},"staticQueryHashes":["251939775","288581551","401334301"],"slicesMap":{}}