Parent and Child Pipelines

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

The event execution pipeline architecture provides the capability for a pipeline to initiate the execution of one or more subordinate pipelines in order to process a request. The originating pipeline is known as the "parent" while the subordinate pipeline is called the "child". Web service method calls typically start a parent pipeline while (internal) platform calls start a child pipeline. Child pipelines only process Create, Update, or Delete messages as required by the platform to process the parent pipeline's message. To determine which message is being processed by a child pipeline, you must enable tracing in Microsoft Dynamics CRM.

Some requests that would cause child pipelines to be created are CompoundCreateRequest and CompoundUpdateRequest. For example, a pipeline that processes a CompoundUpdateRequest to update a salesorderdetail quantity would invoke a child pipeline to update the salesorderdetail and another child pipeline to update the associated salesorder total. However, even a simple request, such as CreateRequest for an account, can result in a child pipeline being executed.

When a complex request is processed by a pipeline, the pipeline first executes any registered pre-event plug-ins and the core platform operation. Next, the pipeline starts a child pipeline and temporarily suspends processing until the child pipeline has finished processing its request. Once the child pipeline has completed, the parent pipeline can complete its post-event processing.

Parent and Child Context

Context plays an important role when it comes to parent-child pipeline execution. The context that is passed to plug-ins of the child pipeline will include the parent context that was executed immediately prior to the child pipeline's invocation. This will enable you to track the parent and child pipeline executions and get more information about what is going on. In the CompoundCreateRequest case, if a plug-in is registered for CreateRequest, the plug-in receives the CompoundCreateRequest context in its CreateRequest parent context property.

The input parameters of parent and child pipelines are not affected by this design. The highest level parent pipeline receives input parameters from the initial Request, for example CompoundCreateRequest, while the child pipeline receives input parameters that are passed in by the parent pipeline Request, for example CreateRequest. Child pipeline plug-ins have access to the input parameters of the Request that initially invoked the parent pipeline.

Invocation Source

A plug-in can be registered to be executed from a parent pipeline or a child pipeline. At run time, a plug-in receives information as to how it was invoked through the InvocationSource property of the context that is passed as a parameter to the plug-in.

If you want your plug-in to run regardless of whether a Web service call or an (internal) platform call initiated the pipeline, register your plug-in in a child pipeline. However, do not use the IPluginExecutionContext.CreateCrmService or IPluginExecutionContext.CreateMetadataService methods if you are writing code for a plug-in in that is used in a child pipeline. In a child pipeline, you must instantiate the CrmService or MetadataService manually.


The following code example shows how to create a CrmService proxy for plug-ins that execute in the child pipeline.

/// <param name="context">The execution context that was passed to the plug-in's Execute method.</param>
/// <param name="flag">Set to True to use impersonation.</param>
/// <returns>A CrmServce instance.</returns>
private CrmService CreateCrmService(IPluginExecutionContext context, Boolean flag)
    CrmAuthenticationToken authToken = new CrmAuthenticationToken();
    authToken.AuthenticationType = 0;
    authToken.OrganizationName = context.OrganizationName;

    // Include support for impersonation.
    if (flag)
        authToken.CallerId = context.UserId;
        authToken.CallerId = context.InitiatingUserId;

    CrmService service = new CrmService();
    service.CrmAuthenticationTokenValue = authToken;
    service.UseDefaultCredentials = true;

     // Include support for infinite loop detection.
    CorrelationToken corToken = new CorrelationToken();
    corToken.CorrelationId = context.CorrelationId;
    corToken.CorrelationUpdatedTime = context.CorrelationUpdatedTime;
    corToken.Depth = context.Depth;

    RegistryKey regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\MSCRM");

    service.Url = String.Concat(regkey.GetValue("ServerUrl").ToString(), "/2007/crmservice.asmx");
    service.CorrelationTokenValue = corToken;

    return service;

Note that instantiating the Web services may cause your child pipeline plug-in to execute slower than a parent pipeline plug-in.

See Also


© 2010 Microsoft Corporation. All rights reserved.