Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom workflow how to get the execution entity

This is my first custom WF for CRM 2011, and this needed to be a generic EF for any entity, I would like to know how to get the execution entity from the context or if not possible, any idea would be very nice.

I start the WF like this:

public class WFIntegracao: CodeActivity
    {

        protected override void Execute(CodeActivityContext context)
        {

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


        }
    }
like image 485
Edilson Avatar asked Jul 30 '12 12:07

Edilson


People also ask

Can we debug custom workflow?

Profile a workflow activity This will open the Profiler Settings dialog which will provide the following options: Select the Workflow or Custom action that contains the workflow activity you want to debug. Select the specific steps within that workflow or custom action that you want to debug.

Can we use pre image and post image in a custom workflow activity?

Now we can also read Pre Images and Post Images in the workflow using Execution Context. It uses the same Plug-in Architecture and hence we can use it to read Pre Images and Post Images. However, this concept is not documented in the SDK so it might be unsupported.

How can you get the plugin tracing information in CRM?

To enable trace logging you can programmatically update this value or in the web application navigate to Settings > Administration > System Settings. In the Customization tab, locate the drop-down menu labeled Enable logging to plug-in trace log and select one of the available options.

Which class is a custom workflow extension's Execute method derived?

Custom workflow activities require creating a . NET Framework assembly that includes one or more classes that are derived from the abstract CodeActivity Class. This class provides the Execute(CodeActivityContext) Method called by the Dataverse platform when the activity is executed.


2 Answers

IWorkflowContext should contain the information you require.

IWorkflowContext contexto = context.GetExtension<IWorkflowContext>();
String entityName = contexto.PrimaryEntityName;
Guid entityId = contexto.PrimaryEntityId;

MSDN IWorkflowContext

like image 150
James Wood Avatar answered Sep 20 '22 23:09

James Wood


I've not made a workflow for a entities of an unspecified type before, however you might be able to alter this code to do so; this is for a contact reference:

[RequiredArgument]
[Input("Contact")]
[ReferenceTarget("contact")]
public InArgument<EntityReference> Contact { get; set; }

protected override void Execute(CodeActivityContext context)
{
    ContactReference = Contact.Get(context);
    if (ContactReference == null)
        throw new InvalidPluginExecutionException("Contact reference is null.");

    DoSomething();
}

Note that I have explicitly stated that the expected input type with be a contact entity reference. You might be able to exclude the ReferenceTarget attribute in order to lift this restriction. You could determine the type later on by simply looking at the LogicalName member of the result of the .Get(), so in the example it'd be:

string entityType = ContactReference.LogicalName;
like image 23
Alec Avatar answered Sep 20 '22 23:09

Alec