web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Dynamix Academy / Custom Workflow Activity in...

Custom Workflow Activity in Dynamics 365

Abhishek Dhoriya Profile Picture Abhishek Dhoriya 1,013

Custom Workflow Activity In Dynamics 365 are reusable activities that can be added to a configured workflow business process. If a custom logic is to be reused multiple times and needs to be configured by power users, then custom workflow activities is the way to go.

Custom Workflow Activity In Dynamics 365 have input and output parameters, making them ideal for data processing and returning computed values.

Types of workflows in Dynamics 365

Workflows can be categorized into the following:

  1. Out-of-box workflows in Dynamics 365: This type of workflow is provided by default in Microsoft Dynamics CRM out-of-box components. Workflows can be fired on create, update, delete, and on-demand. These workflows can be customized and created without writing code.
  2. Custom workflows activity in Dynamics 365: Out-of-box components can be extended and customized by using .NET, and more complex business operations can be done. These workflows are called custom workflows.

Step by Step Create Custom Workflow Activity in Dynamics 365 CRM

Visual Studio Project Setup

  1. Start Visual Studio.
  2. Create a new solution by selecting New | Project from the File menu.
  3. In the New Project dialog, select Blank Solution from the Visual Studio Solutions templates.
  4. Ensure that the selected .NET framework version matches the recommended version of your Dynamics 365 instance. In our example, Dynamics 365 uses .NET 4.5.2.
  5. Give your solution a name, following your project’s convention. DynamixAcademyExtensions in the Name field.
  6. It is highly recommended that you keep the Add to source control checkbox ticked to store your source code in source control:
  7. Click on OK.
  8. Right-click on your solution in the Visual Studio Solution explorer window and select Add | New Project.
  9. Select Class Library and give your project the name DynamixAcademyCustomWorkflowDemo.
  10. Click on OK.
  11. Right-click on your new project’s references and select Manage NuGet Packages….
  12. Search for CRM XrmTooling core assemblies using the top-right search field in the Manage Nuget Packages dialog:
  13. Locate the Microsoft.CrmSdk.XrmTooling.CoreAssemblies package that matches your Dynamics CRM instance version and install it by clicking on the Install button.
  14. Click on the I Accept button after having read and agreed to the license details in the License Acceptance dialog.
  15. Right-click on your project and select properties.
  16. Click on the Sign the assembly tick box in the Signing tab and select an existing signing key, or create a new one. You can optionally create a password for your signing key.

Dynamics 365 Custom Workflow Activity Code

  1. Add the following using statements to your CustomWorkflowDemo.cs file:
    • using Microsoft.Xrm.Sdk.Workflow;
    • using System.Activities;
  2. Inherit from CodeActivity instead of implementing IPlugin, as follows:
    • public class UpdateActivities : CodeActivity 
  3. Add the following workflow input parameter:
    • [Input("Account Guid")] 
      [Default("00000000-0000-0000-0000-000000000000")]
      public InArgument<string> AccountGuid { get; set; }
  4. Change the signature of the Execute method to the following line of code:
    • protected override void Execute(CodeActivityContext executionContext) 
  5. Replace the initialization of the tracing service, the organization service, and the organization service context with the following piece of code:
    • var tracingService = 
      executionContext.GetExtension<ITracingService>();

       

      var context = executionContext.GetExtension<IWorkflowContext>();
      var serviceFactory =
      executionContext.GetExtension<IOrganizationServiceFactory>();
      _organizationService =
      serviceFactory.CreateOrganizationService(context.UserId);

  6. Replace the account and account ID instantiation with the following, and add the trace statement:
    • var input = AccountGuid.Get<string>(executionContext);
      var accountId = input == Guid.Empty.ToString().Trim('{').Trim('}') ?
      context.PrimaryEntityId : Guid.Parse(input);
      tracingService.Trace("Input value {0}", input);

       

      var emails = GetEmails(accountId);

  7. Remove the catch fault exception block.
  8. Then build and register the Custom Workflow Activity in Dynamics 365 Organization using Plugin Registration Tool

The post Custom Workflow Activity in Dynamics 365 appeared first on Dynamix Academy.

Comments

*This post is locked for comments