Sunday, July 24, 2022

Custom Workflow Activity in Dynamics 365

Step 1- Create New Project

In Visual Studio create a new project of type Class Library & select framework version 4.7.1. This might change for future versions.

Step 2 - Add Required Packages

using System;

using System.Activities;

using Microsoft.Xrm.Sdk.Workflow;

Step 3 - Create Class with name of CustomePlugin 

namespace Banne.Autonumber.BannePlugins

{

    public class CustomePlugin : CodeActivity

    {    

     }

}

Step 4 - Add Input/Output Parameters

using System;

using System.Activities;

using Microsoft.Xrm.Sdk.Workflow;

namespace Banne.Autonumber.BannePlugins

{

    public class CustomePlugin : CodeActivity

    {

        [RequiredArgument]

        [Input("Input Text")]

        public InArgument<string> InputText { get; set; }

        [Output("Word Count")]

        public OutArgument<int> CountOfWords { get; set; }

        protected override void Execute(CodeActivityContext context)

        {

            this.CountOfWords.Set(

                context,

                this.InputText.Get<string>(context).Split(

                    new char[] { ' ', '\r', '\n' },

                    StringSplitOptions.RemoveEmptyEntries).Length);

        }

    }

}

Step 5 - Signing the Assembly


Go to properties then find Signing option. Choose sign the assembly and give key.



Step 6 - Register the Assembly in Dynamics 365



Step 7 - Consuming Custom Workflow Activity in Workflow Process

This workflow calling customeplugin and updating the records

Fig1. add custom plugin step

 


Fig2. add update step


Fig 3. Set Input value for Custom Plugin


Fig4. Set output value from Custom Plugin







Testing the Workflow

Calling workflow to find the total number of words in Name filed contains

Output:






No comments:

Post a Comment