Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Microsoft CRM workflow code activity to retrieve various useful parameters for the current executing context.
public class GetEntityParametersCodeActivity : CodeActivity
{
[Output("PrimaryEntityID")]
[ArgumentDescription("Primary Entity ID.")]
public OutArgument<string> PrimaryEntityId { get; set; }
[Output("PrimaryEntityName")]
[ArgumentDescription("Primary Entity Name.")]
public OutArgument<string> PrimaryEntityName { get; set; }
[Output("SecondaryEntityName")]
[ArgumentDescription("Secondary Entity Name.")]
public OutArgument<string> SecondaryEntityName { get; set; }
[Output("Request Id")]
[ArgumentDescription("Request ID.")]
public OutArgument<string> RequestId { get; set; }
[Output("Correlation Id")]
[ArgumentDescription("Correlation ID.")]
public OutArgument<string> CorrelationId { get; set; }
[Output("InitiatingUser Id")]
[ArgumentDescription("InitiatingUser ID.")]
public OutArgument<string> InitiatingUserId { get; set; }
[Output("Operation Id")]
[ArgumentDescription("Operation ID.")]
public OutArgument<string> OperationId { get; set; }
protected override void Execute(CodeActivityContext executionContext)
{
//Create the workflow context
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
if (context == null)
throw new InvalidPluginExecutionException("Failed to retrieve workflow context.");
//Save off the values
PrimaryEntityId.Set(executionContext, context.PrimaryEntityId.ToString());
if(context.RequestId.HasValue)
RequestId.Set(executionContext, context.RequestId.Value.ToString());
PrimaryEntityName.Set(executionContext, context.PrimaryEntityName);
SecondaryEntityName.Set(executionContext, context.SecondaryEntityName);
CorrelationId.Set(executionContext, context.CorrelationId.ToString());
InitiatingUserId.Set(executionContext, context.InitiatingUserId.ToString());
OperationId.Set(executionContext, context.OperationId.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.