locked
CRM 2013: Differentiate between create and update in a WFA plugin (C#) RRS feed

  • Question

  • 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

    Wednesday, May 6, 2015 1:32 AM

Answers

  • 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


    • Edited by xjomanx Wednesday, May 6, 2015 7:05 AM
    • Marked as answer by Hasibur Rahman Friday, March 25, 2016 7:46 PM
    Wednesday, May 6, 2015 6:51 AM
  • 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

    Wednesday, May 6, 2015 7:00 AM
  • Thanks - answer provided by xjomanx worked


    Hasibur Rahman

    Friday, March 25, 2016 7:47 PM

All replies

  • 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


    • Edited by xjomanx Wednesday, May 6, 2015 7:05 AM
    • Marked as answer by Hasibur Rahman Friday, March 25, 2016 7:46 PM
    Wednesday, May 6, 2015 6:51 AM
  • 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

    Wednesday, May 6, 2015 7:00 AM
  • Thanks - answer provided by xjomanx worked


    Hasibur Rahman

    Friday, March 25, 2016 7:47 PM