Writing a simple custom workflow activity in CRM 4.0


Let’s create our first Custom Workflow Activity for CRM 4.0.

Check this post as well

https://nishantrana.wordpress.com/2008/10/30/custom-workflow-activities-in-crm-40/

We’ll take here a very simple scenario just to understand how to write custom activity.

This Custom Activity will take as input First Name and Last Name from an entity ( say Lead) and will update it’s description attribute with (First Name + Last Name).

Create a new Workflow Activity Library within workflow project type in Visual Studio.

(Keep the version as 3.0)

Name it MyFirstCustomWFlowActivity

Add references to Microsoft.crm.sdk.dll and Microsoft.crm.sdktypeproxy.dll.

Add the following line of code in your Activity1.cs.

using Microsoft.Crm.Workflow;

using Microsoft.Crm.Sdk;

We are creating a simple activity, so here we can have our class inherit from Activity class instead of SequenceActivity.

Delete the following class Activity1.Designer.cs as our simple custom activity doesn’t require that.


Decorate the class with CrmWorkflowActivity attribute

The first parameter is the user friendly name of the custom activity that will appear in the Workflow Editor and second parameter is the name of group, it can be used for grouping similar custom workflow activity.

namespace MyFirstCustomWFlowActivity

{

[CrmWorkflowActivity(“Get First and Last Name”, “Custom Steps”)]

public class Activity1: Activity

{

}

}

Now create three dependency properties, two as input for first name and last name and one as output where we will have full name i.e. first name and last name combined.

To create dependency property

Right click inside the visual studio editor then select insert snippet and followed by Workflow then DependencyProperty – Property.

We have used CrmInput and CrmOutput Attribute to make the dependency property visible within the workflow editor and to provide a user friendly name to them.

public static DependencyProperty FirstNameProperty = System.Workflow.ComponentModel.DependencyProperty.Register(“FirstName”, typeof(string), typeof(Activity1));

[CrmInput(“First Name”)]

public string FirstName

{

get

{

return ((string)(base.GetValue(Activity1.FirstNameProperty)));

}

set

{

base.SetValue(Activity1.FirstNameProperty, value);

}

}

public static DependencyProperty LastNameProperty = System.Workflow.ComponentModel.DependencyProperty.Register(“LastName”, typeof(string), typeof(Activity1));

[CrmInput(“Last Name”)]

public string LastName

{

get

{

return ((string)(base.GetValue(Activity1.LastNameProperty)));

}

set

{

base.SetValue(Activity1.LastNameProperty, value);

}

}

public static DependencyProperty FullNameProperty = System.Workflow.ComponentModel.DependencyProperty.Register(“FullName”, typeof(string), typeof(Activity1));

[CrmOutput(“Full Name”)]

public string FullName

{

get

{

return ((string)(base.GetValue(Activity1.FullNameProperty)));

}

set

{

base.SetValue(Activity1.FullNameProperty, value);

} }

Now comes the main part wherein we will override the Execute method and place our custom code to combine the first name and second name.

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

this.FullName = this.FirstName + this.LastName;

return ActivityExecutionStatus.Closed;

}

Now Sign the assembly

Right Click the project in Solution Explorer

Select Properties

Select Signing

Check Sign The Assembly Check box and Select an existing or new file.

Now build the assesbly.

Now we’ll register the assembly

Open the plugin registration tool

Select Register-Register New Assembly and Select the custom workflow assembly there (MyFirstCustomWFlowActivity.dll)

Click on Register Selected Plugins button to register it in the database.

Now open CRM and go to settings then workflow and create a new workflow there.

In Workflow editor you can see our custom steps group at Add Step.

Now you can proceed as you would with other workflow and add your business logic around the custom workflow activity.

Within Add Step you would be able to set value for first name and last name property within the form assistant panel.

And than we can add an Update step wherein we can get the fullname output property within local values section inside form assistant panel.

Bye..

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

2 thoughts on “Writing a simple custom workflow activity in CRM 4.0”

Please share your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Dynamics 365 Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Knowhere365

Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM