none
update plugin in crm 2011

    Question

  • hi everyone,

    i create a plugin which is succesfully work on create event and i want also work this plugin when the entity is update.

    i have created a new step and choose update(pre operation mode) and i give orders to these two event.

    1-create record.(it works on create event post operation mode)

    2-update record. (pre operation mode)

    when i try to create or update a record it gives error. business process error.

    errror log below

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The given key was not present in the dictionary.Detail:
    <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
      <ErrorCode>-2147220891</ErrorCode>
      <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
        <KeyValuePairOfstringanyType>
          <d2p1:key>CallStack</d2p1:key>
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.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.ExecuteInternal(IInProcessOrganizationServiceFactory serviceFactory, IPlatformMessageDispatcherFactory dispatcherFactory, String messageName, String requestName, Int32 primaryObjectTypeCode, Int32 secondaryObjectTypeCode, ParameterCollection fields, CorrelationToken correlationToken, CallerOriginToken originToken, UserAuth userAuth, Guid callerId, Guid transactionContextId, Int32 invocationSource, Nullable`1 requestId, Version endpointVersion)
       at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, UserAuth userAuth, Guid targetUserId, Boolean traceRequest, OrganizationContext context, Boolean returnResponse)
       at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.ExecuteRequest(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)
       at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)</d2p1:value>
        </KeyValuePairOfstringanyType>
        <KeyValuePairOfstringanyType>
          <d2p1:key>OperationStatus</d2p1:key>
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
        </KeyValuePairOfstringanyType>
      </ErrorDetails>
      <Message>The given key was not present in the dictionary.</Message>
      <Timestamp>2013-03-08T12:51:56.8386763Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText>

    [SamplePlugins: Plug_ins.AccountNumberPlugin]
    [73ac7895-ed87-e211-9646-00505683000f: Plug_ins.AccountNumberPlugin: Update of new_test]


    </TraceText>
    </OrganizationServiceFault>


    Crm Software Specialist


    • Edited by devcrm Monday, March 11, 2013 9:29 AM
    Friday, March 08, 2013 12:57 PM

Answers

  • The line below will only work in a post-event on the Create message. For other messages and stages, use context.PrimaryEntityId to get the Id of the current record

    Guid OppID = new Guid(context.OutputParameters["id"].ToString());
    


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by devcrm Monday, March 11, 2013 9:28 AM
    Friday, March 08, 2013 4:49 PM

All replies

  • can i use common plugin both update and create event?

    Crm Software Specialist

    Friday, March 08, 2013 1:16 PM
  • You can use one plugin for both the Create and Update event.

    The error indicates you're trying to access a member of a collection that doesn't exist. This is most likely to be either an InputParameter or OutputParameter (for example, the Id OutputParameter only exists in the Create event, on a post stage), or an attribute of the Target entity.

    Either post your code here, or debug it to find the line, and the collection member you're searching for, that throws the error


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, March 08, 2013 3:38 PM
  • The line below will only work in a post-event on the Create message. For other messages and stages, use context.PrimaryEntityId to get the Id of the current record

    Guid OppID = new Guid(context.OutputParameters["id"].ToString());
    


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by devcrm Monday, March 11, 2013 9:28 AM
    Friday, March 08, 2013 4:49 PM
  • The line below will only work in a post-event on the Create message. For other messages and stages, use context.PrimaryEntityId to get the Id of the current record

    Guid OppID = new Guid(context.OutputParameters["id"].ToString());


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    thx worked well: )
    • Edited by devcrm Monday, March 11, 2013 9:28 AM
    Monday, March 11, 2013 8:10 AM