CRM 2011将潜在客户与广告系列响应相关联

时间:2014-02-21 15:33:14

标签: vb.net dynamics-crm-2011

在我们公司,我们有一个使用CRM Web服务的应用程序。 自从我们从CRM 4.0升级到CRM 2011以来,我正在尝试将我们的代码迁移到新的CRM 2011.此外,我必须阻止使用强类型。因此,我正在使用CRM 2011 Web Service提供的Entity-Class的所有实体。

我们的应用程序执行以下操作:

  1. 从HTML表单创建潜在客户
  2. 制作广告系列响应并将其与潜在客户
  3. 相关联
  4. 将广告系列响应与特定广告系列相关联
  5. 这是CRM 4.0代码:

    Dim lookup As New Lookup()
    lookup.Value = New Guid(linkCampaignGuid)
    lookup.type = "campaign"
    
    Dim activity As New activityparty()
    activity.partyid = New Lookup()
    activity.partyid.type = "lead"
    ' the CreateLead method creates a lead and returns its guid
    ' linkCustomer is the object wich is filled by the HTML form
    activity.partyid.Value = New Guid(CreateLead(linkCustomer))
    
    Dim cr As New campaignresponse()
    cr.regardingobjectid = lookup
    cr.customer = New activityparty() {activity}
    
    ' my CrmService object
    _service.Create(cr)
    


    到目前为止CRM 2011代码:

    Dim lookup As New EntityReference()
    lookup.LogicalName = "campaign"
    lookup.Id = New Guid(linkCampaignGuid)
    
    Dim lead As New EntityReference()
    lead.LogicalName = "lead"
    lead.Id = New Guid(CreateLead(linkCustomer))
    
    Dim activity As New Entity
    activity.LogicalName = "activityparty"
    activity.Id = lead.Id
    activity.Attributes = New AttributeCollection
    activity.Attributes.Add(New KeyValuePair(Of String, Object)("partyid", lead))
    
    Dim campaignResponse As New Entity
    campaignResponse.LogicalName = "campaignresponse"
    campaignResponse.Attributes = New AttributeCollection
    campaignResponse.Attributes.Add(New KeyValuePair(Of String, Object)("regardingobjectid", lookup))
    campaignResponse.Attributes.Add(New KeyValuePair(Of String, Object)("customer", activity))
    
    _service.Create(campaignResponse)
    

    制作广告系列响应,将其与广告系列相关联,然后创建潜在客户。 我的问题是,广告系列响应和潜在客户之间的联系无效。

    我感谢任何帮助!

    更新:

    最后,在尝试了几乎所有事情后,我找到了一种方法让它发挥作用:

    Dim campaignId As Guid = New Guid(linkCampaignGuid)
    Dim leadId As Guid = New Guid(CreateLead(linkCustomer))
    
    Dim campaignReference As New EntityReference("campaign", campaignId)
    Dim leadReference As New EntityReference("lead", leadId)
    
    Dim activityParty As New Entity("activityparty")
    activityParty.AddAttribute("partyid", leadReference)
    
    Dim entityCollection As New EntityCollection()
    entityCollection.EntityName = "activityparty"
    entityCollection.Entities.Add(activityParty)
    
    Dim campaignResponse = New Entity("campaignresponse")
    campaignResponse.Attributes.Add("regardingobjectid", campaignReference)
    campaignResponse.Attributes.Add("customer", entityCollection)
    
    _service.Create(campaignResponse)
    

1 个答案:

答案 0 :(得分:0)

我认为错误就在这一行:

campaignResponse.Attributes.Add(New KeyValuePair(Of String, Object)("customer", activity))

CRM 2011的customer字段是一个简单的查找,因此请尝试直接设置主要参考:

campaignResponse.Attributes.Add(New KeyValuePair(Of String, Object)("customer", lead))

此外,我建议以这种方式重写代码(更具可读性)

Dim campaignId As Guid
campaignId = New Guid(linkCampaignGuid)

Dim leadId As Guid
leadId = New Guid(CreateLead(linkCustomer))

Dim campaignReference = New EntityReference("campaign", campaignId)
Dim leadReference = New EntityReference("lead", leadId)

Dim campaignResponse = New Entity("campaignresponse")
campaignResponse.Attributes.Add("regardingobjectid", campaignReference)
campaignResponse.Attributes.Add("customer", leadReference)

_service.Create(campaignResponse);