简体   繁体   中英

Dynamics CRM 2016 Create and Qualify a Lead Programmatically C#

I'm trying to create a lead entity programmatically, and I have read that there is no more special messages for special fields in dynamics crm 2016.

So, I retrieve data from a dynamics crm server and I insert it in another crm server, without using special messages just like below:

account["statecode"] = new OptionSetValue(1); //inactive
account["statuscode"] = new OptionSetValue(2); //inactive

The problem is a lead record that has a the value "1" in statecode which means is a Qualified lead, and a statuscode that has a value "3" which means also Qualified.

Any way, when I tried to do the insert an error raised with the following message:

3 is not a valid status code for state code LeadState.Open

fyi, LeadState.Open has a value "0" , even though the lead state as I mention before is "1".

I don't know what is exactly the problem.

You should use the QualifyLeadRequest as documented in the SDK . This message, unlike SetState has not been marked for deprecation. The qualify lead workflow is more complex than the set state process because it consists of (optionally) creating and linking to account, contact, and opportunity records.

Here is an example from SDK of qualifying a lead to create an opportunity with an existing account .

            // Qualify the second lead, creating an opportunity from it, and not
            // creating an account or a contact.  We use an existing account for the
            // opportunity customer instead.
            var qualifyIntoOpportunityReq = new QualifyLeadRequest
            {
                CreateOpportunity = true,
                OpportunityCurrencyId = currencyId,
                OpportunityCustomerId = new EntityReference(
                    Account.EntityLogicalName,
                    _accountId),
                Status = new OptionSetValue((int)lead_statuscode.Qualified),
                LeadId = new EntityReference(Lead.EntityLogicalName, _lead2Id)
            };

            var qualifyIntoOpportunityRes =
                (QualifyLeadResponse)_serviceProxy.Execute(qualifyIntoOpportunityReq);
            Console.WriteLine("  The second lead was qualified.");

            foreach (var entity in qualifyIntoOpportunityRes.CreatedEntities)
            {
                NotifyEntityCreated(entity.LogicalName, entity.Id);
                if (entity.LogicalName == Opportunity.EntityLogicalName)
                {
                    _opportunityId = entity.Id;
                }
            }

The example, from which this code is taken, has more details: https://msdn.microsoft.com/en-us/library/hh547458.aspx .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM