CRM 4.0 FAQ > Workflow - Custom Code > How do I get access to the triggering entity information?
CRM when you configure the workflow you identify what the primary entity will be and the triggering message.
Using that information CRM will launch an instance in workflow that will cause your custom activity to be invoked. As part of building a cusotm activity you will override the Execute method on the activity and provide your logic. Passed as a parameter as you can see below is the ActivityExecutionContext for the current request.
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
ActivityExecutionContext is not CRM specific its Windows Workflow Foundation specific and gives you basic info about your current workflow instance and access to get services.
Using the ActivityExecutionContext we can call the GetService method to get the IContextService which is a CRM provided Workflow Service that gives you access to the CRM specific data for your request.
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));IWorkflowContext context = contextService.Context;
From the IWorkflowContext you can access things like the primary entity data, the MessageName that triggered the workflow instance and more.
Last updated on October 3, 2007 by David Yack
