Skip to content

Instantly share code, notes, and snippets.

@johnnycardy
Last active September 26, 2022 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnnycardy/3ec2726d3254efea96e7fc72ab8a5657 to your computer and use it in GitHub Desktop.
Save johnnycardy/3ec2726d3254efea96e7fc72ab8a5657 to your computer and use it in GitHub Desktop.
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