{"id":37176,"date":"2023-11-19T16:23:27","date_gmt":"2023-11-19T10:53:27","guid":{"rendered":"https:\/\/techmasala.addastudents.com\/dev\/?p=37176"},"modified":"2023-11-19T16:25:17","modified_gmt":"2023-11-19T10:55:17","slug":"how-to-create-custom-workflows-in-microsoft-crm","status":"publish","type":"post","link":"https:\/\/techmasala.addastudents.com\/dev\/how-to-create-custom-workflows-in-microsoft-crm\/","title":{"rendered":"How to Create Custom Workflows in Microsoft CRM"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Microsoft CRM provides a powerful platform for automating business processes through workflows. Custom workflows allow you to extend the capabilities of out-of-the-box workflows to handle more complex business scenarios. In this article, you will learn how to create custom workflows in Microsoft CRM using a code example.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Prerequisites<\/strong>:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before you begin, ensure you have the following prerequisites:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Microsoft CRM 2011 or later<\/li>\n\n\n\n<li>Visual Studio 2010 or later<\/li>\n\n\n\n<li>Windows SDK for .NET Framework 4<\/li>\n\n\n\n<li>Microsoft.CrmSdk.Workflow NuGet package<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Creating a Custom Workflow Activity<\/strong>:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Custom workflow activities are reusable components that encapsulate business logic for use in workflows. To create a custom workflow activity, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create a Class Library project in Visual Studio.<\/strong><\/li>\n\n\n\n<li><strong>Add the Microsoft.CrmSdk.Workflow NuGet package to the project.<\/strong><\/li>\n\n\n\n<li><strong>Create a class that inherits from the CodeActivity class.<\/strong><\/li>\n\n\n\n<li><strong>Define the input and output parameters for the activity.<\/strong><\/li>\n\n\n\n<li><strong>Implement the Execute method, which contains the business logic for the activity.<\/strong><\/li>\n\n\n\n<li><strong>Sign the assembly using a strong name key.<\/strong><\/li>\n\n\n\n<li><strong>Build the project and deploy the assembly to the CRM server.<\/strong><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example Code<\/strong>:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of a simple custom workflow activity that sends an email notification when an account record is created:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class SendAccountNotificationActivity : CodeActivity\n{\n    public new InArgument&lt;Entity> Target { get; set; }\n\n    public new InArgument&lt;string> FromAddress { get; set; }\n\n    public new InArgument&lt;string> ToAddress { get; set; }\n\n    public new InArgument&lt;string> Subject { get; set; }\n\n    public new InArgument&lt;string> Body { get; set; }\n\n    protected override void Execute(CodeActivityContext executionContext)\n    {\n        var account = Target.Get(executionContext);\n        var fromAddress = FromAddress.Get(executionContext);\n        var toAddress = ToAddress.Get(executionContext);\n        var subject = Subject.Get(executionContext);\n        var body = Body.Get(executionContext);\n\n        \/\/ Send email notification\n        using (var smtpClient = new SmtpClient())\n        {\n            var mailMessage = new MailMessage(fromAddress, toAddress, subject, body);\n            smtpClient.Send(mailMessage);\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Registering the Custom Workflow Activity<\/strong>:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Once you have created your custom workflow activity, you need to register it with CRM so that it can be used in workflows. To register the activity, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Open the Plugin Registration Tool in CRM.<\/strong><\/li>\n\n\n\n<li><strong>Click the New button.<\/strong><\/li>\n\n\n\n<li><strong>Select Workflow Activity as the Step Type.<\/strong><\/li>\n\n\n\n<li><strong>Enter a name for the activity and select the assembly containing the activity.<\/strong><\/li>\n\n\n\n<li><strong>Click OK to register the activity.<\/strong><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Using the Custom Workflow Activity in a Workflow<\/strong>:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After registering the custom workflow activity, you can use it in workflows. To add the activity to a workflow, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Open the workflow editor in CRM.<\/strong><\/li>\n\n\n\n<li><strong>Drag and drop the custom workflow activity onto the workflow canvas.<\/strong><\/li>\n\n\n\n<li><strong>Configure the properties of the activity.<\/strong><\/li>\n\n\n\n<li><strong>Save and activate the workflow.<\/strong><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Custom workflows provide a powerful tool for automating complex business processes in Microsoft CRM. By creating custom workflow activities, you can extend the capabilities of workflows to handle a wide range of scenarios. The code example provided in this article demonstrates how to create a simple custom workflow activity that sends an email notification.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft CRM provides a powerful platform for automating business processes through workflows. Custom workflows allow you to extend the capabilities of out-of-the-box workflows to handle more complex business scenarios. In this article, you will learn how to create custom workflows in Microsoft CRM using a code example. Prerequisites: Before you begin, ensure you have the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":37189,"comment_status":"open","ping_status":"open","sticky":true,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70,17,72],"tags":[867],"class_list":["post-37176","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn-technology-free","category-learn-microsoft-dynamics-crm","category-tech","tag-microsoftcrm-customworkflows-workflowautomation-businessprocessautomation-crmdeveloper-codeactivity-pluginregistrationtool"],"_links":{"self":[{"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/posts\/37176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/comments?post=37176"}],"version-history":[{"count":4,"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/posts\/37176\/revisions"}],"predecessor-version":[{"id":37192,"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/posts\/37176\/revisions\/37192"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/media\/37189"}],"wp:attachment":[{"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/media?parent=37176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/categories?post=37176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techmasala.addastudents.com\/dev\/wp-json\/wp\/v2\/tags?post=37176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}