locked
Plugin Business process error RRS feed

  • Question

  • Hi All,

    We are creating opportunity on click of custom button in lead using plugin. 

     var qualifyIntoAccountContactReq = new QualifyLeadRequest
                            {
                                CreateAccount = true,
                                CreateOpportunity = true,
                                CreateContact = true,
                                LeadId = new EntityReference("lead", entity.Id),
                            };

    Getting bellow error while doing so

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: An error occurred in the Plugin.System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: An unexpected error occurred. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).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>OperationStatus</d2p1:key>
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
        </KeyValuePairOfstringanyType>
        <KeyValuePairOfstringanyType>
          <d2p1:key>SubErrorCode</d2p1:key>
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
        </KeyValuePairOfstringanyType>
      </ErrorDetails>
      <Message>An error occurred in the Plugin.System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: An unexpected error occurred. (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).</Message>
      <Timestamp>2015-09-30T04:33:14.5886888Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText>
    [LeadQualify:LeadQualify.qualifyLead]
    [9c0eb808-f765-e511-80cd-a95511b30fc0:LeadQualify.qualifyLead: Update of lead]
    </TraceText>
    </OrganizationServiceFault>

    Can any one suggest me to resolve this issue. 

    Thanks.

    Wednesday, September 30, 2015 4:57 AM

Answers

  • Finally we found the issue and resolved this.It was unable to map currency field so we should pass OpportunityCurrencyId for QualifyLeadRequest to create opportunity. 

    var qualifyIntoAccountContactReq = new QualifyLeadRequest{

    CreateAccount = true,
    CreateContact = true,
    LeadId = new EntityReference("lead", entity.Id),
    CreateOpportunity = true,
    OpportunityCurrencyId = transactionCurrency,
    Status = new OptionSetValue(3)

    };

    • Marked as answer by Ashok Jinkala Thursday, October 1, 2015 11:22 AM
    Thursday, October 1, 2015 11:22 AM

All replies

  • Hello,

    Please provide source code of your plugin.


    Dynamics CRM MVP
    My blog

    Wednesday, September 30, 2015 10:59 AM
    Moderator
  •  Working fine in Online facing problem in onpremise.

    public void Execute(IServiceProvider serviceProvider)
            {
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                service = serviceFactory.CreateOrganizationService(context.UserId);
                // Get the qualified lead
                Entity entity;
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    entity = (Entity)context.InputParameters["Target"];
                    if (entity.LogicalName != "lead") { return; }
                }
                else
                {
                    return;
                }
                try
                {
                    if (entity.Contains("new_qualifylead") && entity.Attributes["new_qualifylead"] != null)
                    {
                        int value = ((OptionSetValue)entity.Attributes["new_qualifylead"]).Value;
       if (value == 1)
                        {
                            var qualifyIntoAccountContactReq = new QualifyLeadRequest
                            {
                                CreateAccount = true,
                                CreateContact = true,
    CreateOpportunity = false,
                                LeadId = new EntityReference("lead", entity.Id),
                            };
                            var qualifyIntoAccountContactRes = (QualifyLeadResponse)service.Execute(qualifyIntoAccountContactReq);
                        }
                        else
                        {
                            var qualifyIntoAccountContactReq = new QualifyLeadRequest
                            {
                                CreateAccount = true,
                                CreateContact = true,
                                LeadId = new EntityReference("lead", entity.Id),
    CreateOpportunity = true,
                            };
                            var qualifyIntoAccountContactRes = (QualifyLeadResponse)service.Execute(qualifyIntoAccountContactReq);
                        }
                    }

                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred in the Plugin." + ex, ex);
                }

            }

    Wednesday, September 30, 2015 12:14 PM
  • Seems that you have other plugin that handles QualifyLead message with name LeadQualify.qualifyLead. And I'm pretty sure that issue comes from it so please publish source code of that plugin as well.

    Dynamics CRM MVP
    My blog



    Wednesday, September 30, 2015 12:25 PM
    Moderator
  • LeadQualify.qualifyLead this plugin is created by me only 

    working fine for bellow condition

       if (value == 1)
                        {
                            var qualifyIntoAccountContactReq = new QualifyLeadRequest
                            {
                                CreateAccount = true,
                                CreateContact = true,
    CreateOpportunity = false,
                                LeadId = new EntityReference("lead", entity.Id),
                            };

    facing problem in else condition.     var qualifyIntoAccountContactReq = new QualifyLeadRequest
                            {
                                CreateAccount = true,
                                CreateContact = true,
                                LeadId = new EntityReference("lead", entity.Id),
    CreateOpportunity = true,
                            };
                            var qualifyIntoAccountContactRes = (QualifyLeadResponse)service.Execute(qualifyIntoAccountContactReq);

    Wednesday, September 30, 2015 1:26 PM
  • Finally we found the issue and resolved this.It was unable to map currency field so we should pass OpportunityCurrencyId for QualifyLeadRequest to create opportunity. 

    var qualifyIntoAccountContactReq = new QualifyLeadRequest{

    CreateAccount = true,
    CreateContact = true,
    LeadId = new EntityReference("lead", entity.Id),
    CreateOpportunity = true,
    OpportunityCurrencyId = transactionCurrency,
    Status = new OptionSetValue(3)

    };

    • Marked as answer by Ashok Jinkala Thursday, October 1, 2015 11:22 AM
    Thursday, October 1, 2015 11:22 AM