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>();
}
}
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.
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.
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.
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.
IWorkflowContext
should contain the information you require.
IWorkflowContext contexto = context.GetExtension<IWorkflowContext>();
String entityName = contexto.PrimaryEntityName;
Guid entityId = contexto.PrimaryEntityId;
MSDN IWorkflowContext
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With