Question

Hasibur Rahman on Wed, 06 May 2015 01:32:22


I have created a plugin (C# code dll) which I am using as step of a custom workflow. I want this workflow to kick in the case both creation and update of a certain field.

Now, I am wondering how in my C# code

protectedoverridevoidExecute(CodeActivityContextexecutionContext)

I could distinguish the new creation of a record and update of an existing record


Hasibur Rahman


Sponsored



Replies

xjomanx on Wed, 06 May 2015 06:51:44


Hi,

You plugin contains steps, which describes, what function (in your plugin) executes.

In plugin code:

base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Update", "Your_Entity", new Action<LocalPluginContext>(ExecutePreYourEntityUpdate)));
base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Create", "Your_Entity", new Action<LocalPluginContext>(ExecutePreYourEntityCreate)));
How it look in visual studio


Jochen- on Wed, 06 May 2015 07:00:17


Hi Hasibur,

Get the object that implements the IWorkflowContext interface via the CodeActivityContext. The IWorkflowContext interface has a public property MessageName you could check.

protectedoverridevoidExecute(CodeActivityContext executionContext){

IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

if(context.MessageName.ToLower().Equals("create"))
	//...
if(context.MessageName.ToLower().Equals("update"))
	//...
}

Hope it helps,

Kind Regards

Hasibur Rahman on Fri, 25 Mar 2016 19:47:33


Thanks - answer provided by xjomanx worked