예제 #1
0
        protected override void ExecuteWorkflowLogic()
        {
            var qualifyLeadRequest = new QualifyLeadRequest()
            {
                CreateAccount         = IsCreateAccont.Get(Context.ExecutionContext),
                CreateContact         = IsCreateContact.Get(Context.ExecutionContext),
                CreateOpportunity     = IsCreateOpportunity.Get(Context.ExecutionContext),
                LeadId                = Lead.Get(Context.ExecutionContext),
                Status                = LeadStatus.Get(Context.ExecutionContext),
                OpportunityCurrencyId = Currency.Get(Context.ExecutionContext)
            };

            if (OpportunityCustomerAccount.Get(Context.ExecutionContext) != null)
            {
                qualifyLeadRequest.OpportunityCustomerId = OpportunityCustomerAccount.Get(Context.ExecutionContext);
            }
            else if (OpportunityCustomerContact.Get(Context.ExecutionContext) != null)
            {
                qualifyLeadRequest.OpportunityCustomerId = OpportunityCustomerContact.Get(Context.ExecutionContext);
            }

            var qualifyLeadResponse = (QualifyLeadResponse)Context.UserService.Execute(qualifyLeadRequest);

            foreach (var createdEntity in qualifyLeadResponse.CreatedEntities)
            {
                switch (createdEntity.LogicalName)
                {
                case "account":
                    Account.Set(Context.ExecutionContext, createdEntity);
                    break;

                case "contact":
                    Contact.Set(Context.ExecutionContext, createdEntity);
                    break;

                case "opportunity":
                    Opportunity.Set(Context.ExecutionContext, createdEntity);
                    break;
                }
            }
        }