private void UpdateProspectDataOnLead(Entity leadRecord, ProspectData prospectData)
 {
     if (prospectData.ProspectGroupId.HasValue && !prospectData.ProspectGroupId.Equals(Guid.Empty))
     {
         leadRecord["fdx_prospectgroup"] = new EntityReference("fdx_prospectgroup", prospectData.ProspectGroupId.Value);
     }
     if (prospectData.PriceListId.HasValue && !prospectData.PriceListId.Equals(Guid.Empty))
     {
         leadRecord["fdx_pricelist"] = new EntityReference("pricelevel", prospectData.PriceListId.Value);
     }
     if (prospectData.Priority.HasValue)
     {
         leadRecord["fdx_prospectpriority"] = prospectData.Priority;
     }
     if (prospectData.Score.HasValue)
     {
         leadRecord["fdx_prospectscore"] = prospectData.Score;
     }
     if (prospectData.Percentile.HasValue)
     {
         leadRecord["fdx_prospectpercentile"] = prospectData.Percentile;
     }
     if (!string.IsNullOrEmpty(prospectData.RateSource))
     {
         leadRecord["fdx_ratesource"] = prospectData.RateSource;
     }
     if (prospectData.PPRRate.HasValue)
     {
         leadRecord["fdx_pprrate"] = new Money(prospectData.PPRRate.Value);
     }
     if (prospectData.SubRate.HasValue)
     {
         leadRecord["fdx_subrate"] = new Money(prospectData.SubRate.Value);
     }
     if (prospectData.Radius.HasValue)
     {
         leadRecord["fdx_prospectradius"] = prospectData.Radius;
     }
     if (prospectData.LastUpdated.HasValue)
     {
         leadRecord["fdx_prospectdatalastupdated"] = prospectData.LastUpdated.Value;
     }
     else
     {
         leadRecord["fdx_prospectdatalastupdated"] = DateTime.UtcNow;
     }
     if (!string.IsNullOrEmpty(prospectData.ProspectScoreBlankMessage))
     {
         leadRecord["fdx_prospectscoreblankmessage"] = prospectData.ProspectScoreBlankMessage;
     }
 }
Ejemplo n.º 2
0
        private ProspectData GetProspectDataFromAccount(Entity account)
        {
            ProspectData prospectData = new ProspectData();

            if (account.Contains("fdx_prospectgroup"))
            {
                prospectData.ProspectGroupId = ((EntityReference)account["fdx_prospectgroup"]).Id;
            }
            if (account.Contains("defaultpricelevelid"))
            {
                EntityReference priceList = (EntityReference)account["defaultpricelevelid"];
                prospectData.PriceListId = priceList.Id;
            }
            if (account.Contains("fdx_prospectpriority"))
            {
                prospectData.Priority = (decimal)account["fdx_prospectpriority"];
            }
            if (account.Contains("fdx_prospectscore"))
            {
                prospectData.Score = (decimal)account["fdx_prospectscore"];
            }
            if (account.Contains("fdx_prospectpercentile"))
            {
                prospectData.Percentile = (decimal)account["fdx_prospectpercentile"];
            }
            if (account.Contains("fdx_ratesource"))
            {
                prospectData.RateSource = (string)account["fdx_ratesource"];
            }
            if (account.Contains("fdx_pprrate"))
            {
                prospectData.PPRRate = ((Money)account["fdx_pprrate"]).Value;
            }
            if (account.Contains("fdx_subrate"))
            {
                prospectData.SubRate = ((Money)account["fdx_subrate"]).Value;
            }
            if (account.Contains("fdx_prospectradius"))
            {
                prospectData.Radius = (int)account["fdx_prospectradius"];
            }
            if (account.Contains("fdx_prospectdatalastupdated"))
            {
                prospectData.LastUpdated = (DateTime)account["fdx_prospectdatalastupdated"];
            }
            if (account.Contains("fdx_prospectscoreblankmessage"))
            {
                prospectData.ProspectScoreBlankMessage = (string)account["fdx_prospectscoreblankmessage"];
            }
            return(prospectData);
        }
        private ProspectData GetProspectDataFromContext(ParameterCollection contextSharedVariable)
        {
            ProspectData prospectData = new ProspectData();

            if (contextSharedVariable.ContainsKey("fdx_prospectgroup"))
            {
                prospectData.ProspectGroupId = (Guid)contextSharedVariable["fdx_prospectgroup"];
            }
            if (contextSharedVariable.ContainsKey("fdx_pricelist"))
            {
                prospectData.PriceListId = (Guid)contextSharedVariable["fdx_pricelist"];
            }
            if (contextSharedVariable.ContainsKey("fdx_prospectpriority"))
            {
                prospectData.Priority = (decimal)contextSharedVariable["fdx_prospectpriority"];
            }
            if (contextSharedVariable.ContainsKey("fdx_prospectscore"))
            {
                prospectData.Score = (decimal)contextSharedVariable["fdx_prospectscore"];
            }
            if (contextSharedVariable.ContainsKey("fdx_prospectpercentile"))
            {
                prospectData.Percentile = (decimal)contextSharedVariable["fdx_prospectpercentile"];
            }
            if (contextSharedVariable.ContainsKey("fdx_ratesource"))
            {
                prospectData.RateSource = (string)contextSharedVariable["fdx_ratesource"];
            }
            if (contextSharedVariable.ContainsKey("fdx_pprrate"))
            {
                prospectData.PPRRate = (decimal)contextSharedVariable["fdx_pprrate"];
            }
            if (contextSharedVariable.ContainsKey("fdx_subrate"))
            {
                prospectData.SubRate = (decimal)contextSharedVariable["fdx_subrate"];
            }
            if (contextSharedVariable.ContainsKey("fdx_prospectradius"))
            {
                prospectData.Radius = (int)contextSharedVariable["fdx_prospectradius"];
            }
            if (contextSharedVariable.ContainsKey("fdx_prospectdatalastupdated"))
            {
                prospectData.LastUpdated = (DateTime)contextSharedVariable["fdx_prospectdatalastupdated"];
            }
            if (contextSharedVariable.ContainsKey("fdx_prospectscoreblankmessage"))
            {
                prospectData.ProspectScoreBlankMessage = (string)contextSharedVariable["fdx_prospectscoreblankmessage"];
            }
            return(prospectData);
        }
Ejemplo n.º 4
0
        private string GetProspectDataString(ProspectData prospectData)
        {
            string traceString = "ProspectGroupName=" + prospectData.ProspectGroupName + Environment.NewLine;

            traceString += "PriceListName=" + prospectData.PriceListName + Environment.NewLine;
            traceString += "Priority=" + Convert.ToString(prospectData.Priority) + Environment.NewLine;
            traceString += "Score=" + Convert.ToString(prospectData.Score) + Environment.NewLine;
            traceString += "Percentile=" + Convert.ToString(prospectData.Percentile) + Environment.NewLine;
            traceString += "RateSource=" + prospectData.RateSource + Environment.NewLine;
            traceString += "PPRRate=" + Convert.ToString(prospectData.PPRRate) + Environment.NewLine;
            traceString += "SubRate=" + Convert.ToString(prospectData.SubRate) + Environment.NewLine;
            traceString += "Radius=" + Convert.ToString(prospectData.Radius) + Environment.NewLine;
            traceString += "ProspectScoreBlankMessage=" + Convert.ToString(prospectData.ProspectScoreBlankMessage) + Environment.NewLine;
            return(traceString);
        }
Ejemplo n.º 5
0
        private ProspectData GetProspectDataFromStub()
        {
            ProspectData prospectData = new ProspectData();

            prospectData.ProspectGroupId = new Guid("9B3945FC-2728-E811-811D-3863BB34CB20");
            prospectData.PriceListId     = new Guid("8A826A97-0B26-E811-811C-3863BB35EF70");
            prospectData.Priority        = Convert.ToDecimal(1);
            prospectData.Score           = Convert.ToDecimal(2);
            prospectData.Percentile      = Convert.ToDecimal(3);
            prospectData.RateSource      = "Stub";
            prospectData.PPRRate         = Convert.ToDecimal(1);
            prospectData.SubRate         = Convert.ToDecimal(2);
            prospectData.Radius          = 2;
            return(prospectData);
        }
Ejemplo n.º 6
0
        private ProspectData GetProspectDataFromWebService(Lead lead)
        {
            ProspectData prospectData = new ProspectData();

            prospectData.ProspectGroupName         = lead.prospectGroup;
            prospectData.PriceListName             = lead.priceListName;
            prospectData.Priority                  = lead.prospectPriority;
            prospectData.Score                     = lead.prspectScore;
            prospectData.Percentile                = lead.prospectPercentile;
            prospectData.RateSource                = lead.rateSource;
            prospectData.PPRRate                   = lead.pprRate;
            prospectData.SubRate                   = lead.subRate;
            prospectData.Radius                    = lead.prospectRadius;
            prospectData.ProspectScoreBlankMessage = lead.prospectScoreBlankMessage;
            return(prospectData);
        }
        public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context        = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            ITracingService         tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            tracingService.Trace("Inside the UpdateProspectData");
            if (context.ParentContext != null && context.ParentContext.SharedVariables.ContainsKey("ProspectData"))
            {
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                Guid leadId = (Guid)context.OutputParameters["id"];
                tracingService.Trace("Lead Id" + leadId.ToString());
                Entity       leadRecord   = new Entity("lead", leadId);
                ProspectData prospectData = GetProspectDataFromContext(context.ParentContext.SharedVariables);
                tracingService.Trace("ProspectscoreBlankMessage :" + prospectData.ProspectScoreBlankMessage);
                UpdateProspectDataOnLead(leadRecord, prospectData);
                IOrganizationService impersonatedService = serviceFactory.CreateOrganizationService(null);
                impersonatedService.Update(leadRecord);
            }
        }
Ejemplo n.º 8
0
 private void CopyLeadProspectDataToSharedVariable(ParameterCollection contextSharedVariable, ProspectData prospectData)
 {
     contextSharedVariable.Add("ProspectData", true);
     if (prospectData.ProspectGroupId.HasValue && !prospectData.ProspectGroupId.Equals(Guid.Empty))
     {
         contextSharedVariable.Add("fdx_prospectgroup", prospectData.ProspectGroupId.Value);
     }
     if (prospectData.PriceListId.HasValue && !prospectData.PriceListId.Equals(Guid.Empty))
     {
         contextSharedVariable.Add("fdx_pricelist", prospectData.PriceListId.Value);
     }
     if (prospectData.Priority.HasValue)
     {
         contextSharedVariable.Add("fdx_prospectpriority", prospectData.Priority);
     }
     if (prospectData.Score.HasValue)
     {
         contextSharedVariable.Add("fdx_prospectscore", prospectData.Score);
     }
     if (prospectData.Percentile.HasValue)
     {
         contextSharedVariable.Add("fdx_prospectpercentile", prospectData.Percentile);
     }
     if (!string.IsNullOrEmpty(prospectData.RateSource))
     {
         contextSharedVariable.Add("fdx_ratesource", prospectData.RateSource);
     }
     if (prospectData.PPRRate.HasValue)
     {
         contextSharedVariable.Add("fdx_pprrate", prospectData.PPRRate);
     }
     if (prospectData.SubRate.HasValue)
     {
         contextSharedVariable.Add("fdx_subrate", prospectData.SubRate);
     }
     if (prospectData.Radius.HasValue)
     {
         contextSharedVariable.Add("fdx_prospectradius", prospectData.Radius);
     }
     if (prospectData.LastUpdated.HasValue)
     {
         contextSharedVariable.Add("fdx_prospectdatalastupdated", prospectData.LastUpdated.Value);
     }
     if (!string.IsNullOrEmpty(prospectData.ProspectScoreBlankMessage))
     {
         contextSharedVariable.Add("fdx_prospectscoreblankmessage", prospectData.ProspectScoreBlankMessage);
     }
 }
Ejemplo n.º 9
0
        public void Execute(IServiceProvider serviceProvider)
        {
            int    step    = 0;
            string url     = "";
            string apiParm = "";

            //Extract the tracing service for use in debugging sandboxed plug-ins....
            step           = 87;
            tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            //Obtain execution contest from the service provider....
            step = 88;
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                step       = 89;
                leadEntity = (Entity)context.InputParameters["Target"];

                if (leadEntity.LogicalName != "lead")
                {
                    return;
                }

                try
                {
                    step = 90;
                    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    service = serviceFactory.CreateOrganizationService(context.UserId);

                    //Format phone numbers to remove special characters....
                    step = 91;
                    this.formatPhoneNumbers();

                    //Initialize lead variables....
                    step      = 92;
                    variables = new LeadAssignment_Variables(leadEntity, service);

                    leadEntity["fdx_createdontime"] = variables.tzTime.Hour;

                    //Set api parameters....
                    step    = 93;
                    apiParm = this.setApiParmFromLeadEntity();

                    //Set Connected lead, existing contact, existinng account and Lead owner based on criteria....
                    if (!variables.isGroupPractice)
                    {
                        EntityCollection entityCollection = new EntityCollection();
                        if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 1)).Entities.Count > 0)
                        {
                            tracingService.Trace("First name, last name and office phone on new lead matches First name, last name and office phone on existing lead");
                            step = 1;
                            this.setConnectedLead(entityCollection.Entities[0]);
                            step = 2;
                            this.setExistingContact(entityCollection.Entities[0], "lead");
                            step = 3;
                            this.setExistingAccount(entityCollection.Entities[0], "lead");
                            step = 4;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 2)).Entities.Count > 0)
                        {
                            tracingService.Trace("First name, last name and office phone on new lead matches First name, last name and office phone on existing contact");
                            step = 5;
                            this.setExistingContact(entityCollection.Entities[0], "contact");
                            step = 6;
                            this.setExistingAccount(entityCollection.Entities[0], "contact");
                            step = 7;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 3)).Entities.Count > 0)
                        {
                            tracingService.Trace("Office Phone on new lead matches office phone on existing lead");
                            step = 8;
                            this.setConnectedLead(entityCollection.Entities[0]);
                            step = 9;
                            this.setExistingAccount(entityCollection.Entities[0], "lead");
                            step = 10;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 4)).Entities.Count > 0)
                        {
                            tracingService.Trace("Email on new lead matches email on existing lead");
                            step = 11;
                            this.setConnectedLead(entityCollection.Entities[0]);
                            step = 12;
                            this.setExistingAccount(entityCollection.Entities[0], "lead");
                            step = 13;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 5)).Entities.Count > 0)
                        {
                            tracingService.Trace("Company name and zipcode on new lead matches company name and zipcode on an account");
                            step = 14;
                            Entity matchedLead = new Entity();
                            matchedLead = this.getAccountMatchedLead(entityCollection.Entities[0]);
                            step        = 15;
                            if (matchedLead.Id != Guid.Empty)
                            {
                                step = 16;
                                this.setConnectedLead(matchedLead);
                            }

                            step = 17;
                            this.setExistingAccount(entityCollection.Entities[0], "account");
                            step = 18;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 6)).Entities.Count > 0)
                        {
                            tracingService.Trace("Company name and zipcode on new lead matches company name and zipcode on a lead");
                            step = 19;
                            this.setConnectedLead(entityCollection.Entities[0]);
                            step = 20;
                            this.setExistingAccount(entityCollection.Entities[0], "lead");
                            step = 21;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 7)).Entities.Count > 0)
                        {
                            tracingService.Trace("Email on new lead matches email on account");
                            Entity matchedLead = new Entity();
                            step        = 22;
                            matchedLead = this.getAccountMatchedLead(entityCollection.Entities[0]);
                            step        = 23;
                            if (matchedLead.Id != Guid.Empty)
                            {
                                step = 24;
                                this.setConnectedLead(matchedLead);
                            }
                            this.setExistingAccount(entityCollection.Entities[0], "account");
                            step = 25;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 8)).Entities.Count > 0)
                        {
                            tracingService.Trace("Email on new lead matches email on existing contact");
                            step = 26;
                            this.setExistingAccount(entityCollection.Entities[0], "contact");
                            step = 27;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 9)).Entities.Count > 0)
                        {
                            tracingService.Trace("Lastname and phone on new lead matches lastname and any phone on contact");
                            step = 28;
                            this.setExistingAccount(entityCollection.Entities[0], "contact");
                            step = 29;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 10)).Entities.Count > 0)
                        {
                            tracingService.Trace("Lastname and phone on new lead matches lastname and any phone on lead");
                            step = 30;
                            this.setConnectedLead(entityCollection.Entities[0]);
                            step = 31;
                            this.setExistingAccount(entityCollection.Entities[0], "lead");
                            step = 32;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 11)).Entities.Count > 0)
                        {
                            tracingService.Trace("Office Phone on new lead matches any phone on a lead");
                            step = 33;
                            this.setConnectedLead(entityCollection.Entities[0]);
                            step = 34;
                            this.setExistingAccount(entityCollection.Entities[0], "lead");
                            step = 35;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 12)).Entities.Count > 0)
                        {
                            tracingService.Trace("Mobile Phone on new lead matches any phone on a lead");
                            step = 36;
                            this.setConnectedLead(entityCollection.Entities[0]);
                            step = 37;
                            this.setExistingAccount(entityCollection.Entities[0], "lead");
                            step = 38;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 13)).Entities.Count > 0)
                        {
                            tracingService.Trace("Office Phone on new lead matches any phone on account");
                            Entity matchedLead = new Entity();
                            step        = 39;
                            matchedLead = this.getAccountMatchedLead(entityCollection.Entities[0]);
                            step        = 40;
                            if (matchedLead.Id != Guid.Empty)
                            {
                                step = 41;
                                this.setConnectedLead(matchedLead);
                            }
                            step = 42;
                            this.setExistingAccount(entityCollection.Entities[0], "account");
                            step = 43;
                            this.setLeadOwner(entityCollection.Entities[0]);

                            //Code added as part of S893 by Meghana on Lead create for Incoming Phone call,web creation/import
                            //wf name - fdx_Lead update Existing Account
                            step = 44;
                            //this.updateExistingAccount(matchedLead.Id);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 14)).Entities.Count > 0)
                        {
                            tracingService.Trace("Mobile Phone on new lead matches any phone on account");
                            Entity matchedLead = new Entity();
                            step        = 45;
                            matchedLead = this.getAccountMatchedLead(entityCollection.Entities[0]);
                            step        = 46;
                            if (matchedLead.Id != Guid.Empty)
                            {
                                step = 47;
                                this.setConnectedLead(matchedLead);
                            }
                            step = 48;
                            this.setExistingAccount(entityCollection.Entities[0], "account");
                            step = 49;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 15)).Entities.Count > 0)
                        {
                            tracingService.Trace("Office Phone on new lead matches any phone on contact");
                            step = 50;
                            this.setExistingAccount(entityCollection.Entities[0], "contact");
                            step = 51;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if ((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 16)).Entities.Count > 0)
                        {
                            tracingService.Trace("Mobile Phone on new lead matches any phone on contact");
                            step = 52;
                            this.setExistingAccount(entityCollection.Entities[0], "contact");
                            step = 53;
                            this.setLeadOwner(entityCollection.Entities[0]);
                        }
                        else if (((entityCollection = CRMQueryExpression.GetLeadEntityCollection(variables, service, 17)).Entities.Count > 0) && ((((OptionSetValue)leadEntity["leadsourcecode"]).Value == 1) || (((OptionSetValue)leadEntity["leadsourcecode"]).Value == 4)))
                        {
                            tracingService.Trace("Assiagn SAE based on zipcode");
                            step = 54;
                            Entity user = entityCollection.Entities[0];
                            step = 55;
                            leadEntity["ownerid"] = new EntityReference("systemuser", user.Id);
                        }
                        else if (((OptionSetValue)leadEntity["leadsourcecode"]).Value == 1 || ((OptionSetValue)leadEntity["leadsourcecode"]).Value == 4)
                        {
                            tracingService.Trace("Set lead Assigned to False and trigger next@bat only for Web Leads (new leads only and not cloned)");
                            variables.leadAssigned = false;
                            step = 56;
                            if (((OptionSetValue)leadEntity["leadsourcecode"]).Value == 1 && !leadEntity.Attributes.Contains("fdx_leadid"))
                            {
                                leadEntity["fdx_snb"] = true;
                            }
                        }
                    }

                    #region Set the address field as per the account if there is an existing account....
                    if (variables.accountid != Guid.Empty)
                    {
                        step = 57;
                        EntityCollection accountCollection = this.getExisitingAccountDetails(variables.accountid);
                        if (accountCollection.Entities.Count > 0)
                        {
                            Entity account = new Entity();
                            account = accountCollection.Entities[0];
                            step    = 58;
                            if (!account.Attributes.Contains("fdx_goldmineaccountnumber"))
                            {
                                step    = 59;
                                apiParm = this.setApiParmFromAccountEntity(account);
                                url     = variables.smartCrmSyncWebServiceUrl + "/lead/createlead?" + apiParm;
                            }
                            else
                            {
                                step = 60;
                                variables.acc_gmaccountno_exist         = true;
                                leadEntity["fdx_goldmineaccountnumber"] = account.Attributes["fdx_goldmineaccountnumber"].ToString();
                                leadEntity["fdx_gonogo"] = account.Attributes["fdx_gonogo"];
                                step = 61;
                                ProspectData prospectData = this.GetProspectDataFromAccount(account);
                                step = 62;
                                CopyLeadProspectDataToSharedVariable(context.SharedVariables, prospectData);
                            }
                        }
                    }
                    else
                    {
                        step = 63;
                        url  = variables.smartCrmSyncWebServiceUrl + "/lead/createlead?" + apiParm;
                    }
                    #endregion

                    #region Call and update from API....
                    tracingService.Trace(url);
                    Lead leadObj = new Lead();
                    if (!variables.acc_gmaccountno_exist)
                    {
                        step = 64;
                        const string token = "8b6asd7-0775-4278-9bcb-c0d48f800112";
                        var          uri   = new Uri(url);
                        step = 65;
                        var request = WebRequest.Create(uri);
                        request.Method        = WebRequestMethods.Http.Post;
                        request.ContentType   = "application/json";
                        request.ContentLength = 0;
                        request.Headers.Add("Authorization", token);

                        step = 66;
                        using (var getResponse = request.GetResponse())
                        {
                            step = 67;
                            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Lead));

                            step    = 68;
                            leadObj = (Lead)serializer.ReadObject(getResponse.GetResponseStream());
                            tracingService.Trace("ProspectScoreBlankMessage :" + leadObj.prospectScoreBlankMessage);
                            if (string.IsNullOrEmpty(leadObj.prospectScoreBlankMessage))
                            {
                                leadObj.prospectScoreBlankMessage = "Valid Address";
                            }

                            step = 69;
                            EntityCollection priceLists = this.GetPriceListByName(leadObj.priceListName, service);
                            step = 70;
                            EntityCollection prospectGroups = this.GetProspectGroupByName(leadObj.prospectGroup, service);
                            step = 71;

                            ProspectData prospectData = this.GetProspectDataFromWebService(leadObj);
                            prospectData.PriceListName = leadObj.priceListName;
                            int lengthoferror = leadObj.prospectScoreBlankMessage.Length;

                            tracingService.Trace("lengthoferror-" + lengthoferror);
                            //if(lengthoferror >= 1500)
                            //{
                            //    string trimerror = leadObj.prospectScoreBlankMessage.Substring(0, 1400);
                            //    leadObj.prospectScoreBlankMessage = leadObj.prospectScoreBlankMessage.Substring(0, 1499);
                            //    tracingService.Trace("trimerrormessage :" + trimerror);
                            //}

                            step = 72;
                            if (priceLists.Entities.Count == 1)
                            {
                                prospectData.PriceListId = priceLists.Entities[0].Id;
                            }

                            step = 73;
                            if (prospectGroups.Entities.Count == 1)
                            {
                                prospectData.ProspectGroupId = prospectGroups.Entities[0].Id;
                            }

                            step = 74;
                            leadEntity["fdx_goldmineaccountnumber"] = leadObj.goldMineId;
                            if (leadObj.goNoGo)
                            {
                                leadEntity["fdx_gonogo"] = new OptionSetValue(756480000);
                            }
                            else
                            {
                                leadEntity["fdx_gonogo"] = new OptionSetValue(756480001);
                            }

                            step = 75;
                            if (variables.accountid != Guid.Empty)
                            {
                                step = 76;
                                IOrganizationService impersonatedService = serviceFactory.CreateOrganizationService(null);

                                step = 77;
                                Entity acc = new Entity("account")
                                {
                                    Id = variables.accountid
                                };
                                acc.Attributes["fdx_goldmineaccountnumber"] = leadObj.goldMineId;
                                acc.Attributes["fdx_gonogo"] = leadObj.goNoGo ? new OptionSetValue(756480000) : new OptionSetValue(756480001);

                                step = 78;

                                this.UpdateProspectDataOnAccount(acc, prospectData);
                                step = 79;
                                impersonatedService.Update(acc);
                            }

                            step = 80;
                            CopyLeadProspectDataToSharedVariable(context.SharedVariables, prospectData);
                            step = 81;
                            tracingService.Trace(GetProspectDataString(prospectData));
                            tracingService.Trace("Prospect Data Updated in AssignLead_Create");
                        }
                    }
                    #endregion

                    #region Condition to assign Lead to Lead Review Team....
                    if (!variables.leadAssigned && !leadObj.goNoGo && ((((OptionSetValue)leadEntity["leadsourcecode"]).Value == 1) || (((OptionSetValue)leadEntity["leadsourcecode"]).Value == 4)))
                    {
                        step = 82;
                        leadEntity["fdx_snb"] = false;
                        QueryExpression teamQuery = CRMQueryExpression.getQueryExpression("team", new ColumnSet("name"), new CRMQueryExpression[] { new CRMQueryExpression("name", ConditionOperator.Equal, "Lead Review Team") });

                        step = 83;
                        EntityCollection teamCollection = service.RetrieveMultiple(teamQuery);

                        step = 84;
                        if (teamCollection.Entities.Count > 0)
                        {
                            Entity team = teamCollection.Entities[0];
                            leadEntity["ownerid"] = new EntityReference("team", team.Id);
                        }

                        tracingService.Trace("Condition to assign Lead to Lead Review Team");
                    }
                    #endregion

                    #region Condition if Cloned Lead: override owner of cloned lead = originating lead's owner

                    if (leadEntity.Attributes.Contains("fdx_leadid"))
                    {
                        step = 85;
                        Entity OriginatingLead = service.Retrieve("lead", ((EntityReference)leadEntity.Attributes["fdx_leadid"]).Id, new ColumnSet("ownerid", "owningteam"));

                        step = 86;
                        if (OriginatingLead.Attributes.Contains("owningteam"))
                        {
                            leadEntity["ownerid"] = new EntityReference(OriginatingLead["owningteam"] != null ? "team" : "systemuser", ((EntityReference)OriginatingLead.Attributes["ownerid"]).Id);
                        }
                        else
                        {
                            leadEntity["ownerid"] = new EntityReference("systemuser", ((EntityReference)OriginatingLead.Attributes["ownerid"]).Id);
                        }

                        tracingService.Trace("Condition if Cloned Lead: override owner of cloned lead = originating lead's owner");
                    }
                    #endregion
                }
                catch (FaultException <OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException(string.Format("An error occurred in the LeadAssignment_Create plug-in at Step {0}.", step), ex);
                }
                catch (Exception ex)
                {
                    tracingService.Trace("LeadAssignment_Create: step {0}, {1}", step, ex.ToString());
                    throw;
                }
            }
        }