locked
Plugin triggering issue RRS feed

  • Question

  • I am triggering a plugin on pre create of orderdetails. It is working fine when I create a orderdetail manually. It is not triggering when I convert a quote into order and ordrdetail is created automatically.

    Can anyone suggest anything?

     

    Thursday, June 10, 2010 2:31 PM

Answers

All replies

  • You probably need to register it for the Child Pipeline.
    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/
    Thursday, June 10, 2010 2:57 PM
  • When I register it for Child Pipeline, I am getting error message.
    Thursday, June 10, 2010 3:00 PM
  • What's the error message?
    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/
    Thursday, June 10, 2010 3:15 PM
  • The error message is likely related to the use of the ICrmService class to creating a connection back to CRM.  This is not allowed/possible with Plugins registered in the child-pipeline.  You need to establish a new function to create this connection for you.  See: http://msdn.microsoft.com/en-us/library/cc151083.aspx
    Dave Berry
    Thursday, June 10, 2010 5:44 PM
    Moderator
  • Please advise how can I fix this issue. I have added the code as well as error message as below:-
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Crm.Sdk;
    using Microsoft.Crm.Sdk.Query;
    using Microsoft.Crm.SdkTypeProxy;
    
    namespace AutoConnectionCreation
    {
      public class AutoConnection : IPlugin
      {
    
        public void Execute(IPluginExecutionContext context)
        {
          ICrmService service = context.CreateCrmService(true);
    
          DynamicEntity entity = (DynamicEntity)context.InputParameters[ParameterName.Target];
          if (entity.Name == EntityName.salesorderdetail.ToString())
          {
            // Get the Quantity
            CrmDecimal counter = (CrmDecimal)entity.Properties["quantity"];
    
            for (int x = 1; x <= Convert.ToInt32(counter.Value); x++)
            {
              DynamicEntity connObject = new DynamicEntity();
              connObject.Name = "new_connection";
              connObject.Properties = new PropertyCollection();
              connObject.Properties.Add(new StringProperty("new_name", x.ToString()));
              connObject.Properties.Add(new CrmNumberProperty("new_srno", new CrmNumber(x)));
              connObject.Properties.Add(new LookupProperty("new_orderid", (Lookup)entity.Properties["salesorderid"]));
              if (entity.Properties.Contains("new_tariffid"))
                connObject.Properties.Add(new LookupProperty("new_tariffid", (Lookup)entity.Properties["new_tariffid"]));
              connObject.Properties.Add(new LookupProperty("new_productid", (Lookup)entity.Properties["productid"]));
    
              service.Create(connObject);
            }
          }
        }
      }
    }
    
    //******************
    //Error Message
    //******************
    
    Log Name:   Application
    Source:    ASP.NET 2.0.50727.0
    Date:     10/06/2010 19:35:39
    Event ID:   1309
    Task Category: Web Event
    Level:     Warning
    Keywords:   Classic
    User:     N/A
    Computer:   Tim.31e.com
    Description:
    Event code: 3005 
    Event message: An unhandled exception has occurred. 
    Event time: 10/06/2010 19:35:39 
    Event time (UTC): 10/06/2010 18:35:39 
    Event ID: 174b0c26cfad48b08efd4b7a56da6a0b 
    Event sequence: 1035 
    Event occurrence: 5 
    Event detail code: 0 
     
    Application information: 
      Application domain: /LM/W3SVC/1/ROOT-1-129206466760586882 
      Trust level: Full 
      Application Virtual Path: / 
      Application Path: C:\Program Files\Microsoft Dynamics CRM\CRMWeb\ 
      Machine name: TIM 
     
    Process information: 
      Process ID: 2320 
      Process name: w3wp.exe 
      Account name: NT AUTHORITY\NETWORK SERVICE 
     
    Exception information: 
      Exception type: TargetInvocationException 
      Exception message: Exception has been thrown by the target of an invocation. 
     
    Request information: 
      Request URL: http://tim:5555/BusinessMobiles/sfa/quotes/edit.aspx?id={60CD76D6-9474-DF11-97FB-0019B9D8525C} 
      Request path: /BusinessMobiles/sfa/quotes/edit.aspx 
      User host address: 172.16.201.9 
      User: 31E\FFiaz 
      Is authenticated: True 
      Authentication Type: Negotiate 
      Thread account name: NT AUTHORITY\NETWORK SERVICE 
     
    Thread information: 
      Thread ID: 3 
      Thread account name: NT AUTHORITY\NETWORK SERVICE 
      Is impersonating: False 
      Stack trace:  at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
      at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
      at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
      at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
      at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IPluginExecutionContext context)
      at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context)
      at Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
      at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
      at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
      at Microsoft.Crm.Extensibility.ExternalMessageDispatcher.Execute(String messageName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, PropertyBag fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
      at Microsoft.Crm.Sdk.RequestBase.Process(Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
      at Microsoft.Crm.Sdk.RequestBase.Process(CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
      at Microsoft.Crm.Sdk.CrmServiceInternal.Execute(RequestBase request, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
      at Microsoft.Crm.Sdk.InProcessCrmService.Execute(Object request)
      at Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.ExecuteInternal()
      at Microsoft.Crm.Application.Platform.ServiceCommands.ConvertQuoteToSalesOrderCommand.Execute()
      at Microsoft.Crm.Application.Platform.Quote.CreateOrder()
      at Microsoft.Crm.Web.SFA.QuoteDetailPage.createOrder(Object sender, DataEventArgs e)
      at Microsoft.Crm.Application.Forms.DataEventProcessor.Raise(FormEventId eventId, FormState state, IUser user, String objectId, Entity entity)
      at Microsoft.Crm.Application.Forms.AppForm.RaiseDataEvent(FormEventId eventId)
      at Microsoft.Crm.Application.Forms.EndUserForm.Initialize(Entity entity)
      at Microsoft.Crm.Application.Forms.CustomizableForm.Execute(Entity entity, String formType)
      at Microsoft.Crm.Web.SFA.QuoteDetailPage.ConfigureForm()
      at Microsoft.Crm.Application.Controls.AppUIPage.OnPreRender(EventArgs e)
      at System.Web.UI.Control.PreRenderRecursiveInternal()
      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
     
     
    Custom event details: Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
     <System>
      <Provider Name="ASP.NET 2.0.50727.0" />
      <EventID Qualifiers="32768">1309</EventID>
      <Level>3</Level>
      <Task>3</Task>
      <Keywords>0x80000000000000</Keywords>
      <TimeCreated SystemTime="2010-06-10T18:35:39.000000000Z" />
      <EventRecordID>8464</EventRecordID>
      <Channel>Application</Channel>
      <Computer>Tim.31e.com</Computer>
      <Security />
     </System>
     <EventData>
      <Data>3005</Data>
      <Data>An unhandled exception has occurred.</Data>
      <Data>10/06/2010 19:35:39</Data>
      <Data>10/06/2010 18:35:39</Data>
      <Data>174b0c26cfad48b08efd4b7a56da6a0b</Data>
      <Data>1035</Data>
      <Data>5</Data>
      <Data>0</Data>
      <Data>/LM/W3SVC/1/ROOT-1-129206466760586882</Data>
      <Data>Full</Data>
      <Data>/</Data>
      <Data>C:\Program Files\Microsoft Dynamics CRM\CRMWeb\</Data>
      <Data>TIM</Data>
      <Data>
      </Data>
      <Data>2320</Data>
      <Data>w3wp.exe</Data>
      <Data>NT AUTHORITY\NETWORK SERVICE</Data>
      <Data>TargetInvocationException</Data>
      <Data>Exception has been thrown by the target of an invocation.</Data>
      <Data>http://tim:5555/BusinessMobiles/sfa/quotes/edit.aspx?id={60CD76D6-9474-DF11-97FB-0019B9D8525C}</Data>
      <Data>/BusinessMobiles/sfa/quotes/edit.aspx</Data>
      <Data>172.16.201.9</Data>
      <Data>31E\FFiaz</Data>
      <Data>True</Data>
      <Data>Negotiate</Data>
      <Data>NT AUTHORITY\NETWORK SERVICE</Data>
      <Data>3</Data>
      <Data>NT AUTHORITY\NETWORK SERVICE</Data>
      <Data>False</Data>
      <Data>  at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
      at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
      at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
      at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
      at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IPluginExecutionContext context)
      at Microsoft.Crm.Extensibility.PluginStep.Execute(PipelineExecutionContext context)
      at Microsoft.Crm.Extensibility.Pipeline.Execute(PipelineExecutionContext context)
      at Microsoft.Crm.Extensibility.MessageProcessor.Execute(PipelineExecutionContext context)
      at Microsoft.Crm.Extensibility.InternalMessageDispatcher.Execute(PipelineExecutionContext context)
      at Microsoft.Crm.Extensibility.ExternalMessageDispatcher.Execute(String messageName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, PropertyBag fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
      at Microsoft.Crm.Sdk.RequestBase.Process(Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
      at Microsoft.Crm.Sdk.RequestBase.Process(CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
      at Microsoft.Crm.Sdk.CrmServiceInternal.Execute(RequestBase request, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId)
      at Microsoft.Crm.Sdk.InProcessCrmService.Execute(Object request)
      at Microsoft.Crm.Application.Platform.ServiceCommands.PlatformCommand.ExecuteInternal()
      at Microsoft.Crm.Application.Platform.ServiceCommands.ConvertQuoteToSalesOrderCommand.Execute()
      at Microsoft.Crm.Application.Platform.Quote.CreateOrder()
      at Microsoft.Crm.Web.SFA.QuoteDetailPage.createOrder(Object sender, DataEventArgs e)
      at Microsoft.Crm.Application.Forms.DataEventProcessor.Raise(FormEventId eventId, FormState state, IUser user, String objectId, Entity entity)
      at Microsoft.Crm.Application.Forms.AppForm.RaiseDataEvent(FormEventId eventId)
      at Microsoft.Crm.Application.Forms.EndUserForm.Initialize(Entity entity)
      at Microsoft.Crm.Application.Forms.CustomizableForm.Execute(Entity entity, String formType)
      at Microsoft.Crm.Web.SFA.QuoteDetailPage.ConfigureForm()
      at Microsoft.Crm.Application.Controls.AppUIPage.OnPreRender(EventArgs e)
      at System.Web.UI.Control.PreRenderRecursiveInternal()
      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    </Data>
     </EventData>
    </Event>
    Thursday, June 10, 2010 6:47 PM
  • I am not happy for this to be marked as answer. If this is the answer than every question has an answer before it's creation.
    Wednesday, July 21, 2010 3:53 PM
  • I marked a post as an answer because it contains all the information necessary to resolve the issue with the child pipeline. Both the post marked as an answer, and the article it references, state that you cannot use the first line in your code ( ICrmService service = context.CreateCrmService(true); ) within a child pipeline.

    I suggest you review the answer, and if that is insufficient then post again to this thread with the updated code. It would also be helpful if you implemented exception handling to identify the SoapException.Detail information, as described at http://msdn.microsoft.com/en-gb/library/bb928443.aspx


    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk
    Wednesday, July 21, 2010 4:17 PM
    Moderator