簡體   English   中英

在 Dynamics CRM 2015 中以編程方式創建 LookupAttributeMetadata

[英]Programmatically creating LookupAttributeMetadata in Dynamics CRM 2015

我即將將 Dynamics CRM 2011 On Premise 實例遷移到 Dynamics CRM 2015 Online。

我正在使用當前的 Dynamics CRM SDK(當前版本 7.1)並成功遷移了自定義屬性,但無法通過CreateAttributeRequest創建的VirtualLookup屬性除外。

接下來,我需要遷移所有關系。 到目前為止,我已經能夠獲得必要的OneToManyRelationshipMetadataManyToManyRelationshipMetadata 但是,對於OneToManyRelationshipMetadata我需要將LookupAttributeMetadata傳遞給CreateAttributeRequest

OneToManyRelationshipRequest request = new OneToManyRelationshipRequest() 
{
    Lookup = new LookupAttributeMetadata() 
    {
        SchemaName = "new_topicid",
        DisplayName = new Label("Subject", 1033),
        Description = new Label("Subject Description", 1033)
    },
    OneToManyRelationship = new OneToManyRelationshipMetadata() 
    {
        ReferencedEntity = "subject",
        ReferencedAttribute = "subjectid",
        ReferencingEntity = "customer",
        ReferencingAttribute = "new_topicid"
    }
}

但是,我得到屬性new_topicid不存在的異常。 這可能是有道理的,因為我在之前的 Attribute 創建過程中不得不跳過它(因為它不能通過CreateAttributeRequest創建)。

有沒有其他方法可以將LookupAttributeMetadataOneToManyRelationshipMetadata / ManyToManyRelationshipMetadata在線遷移到 Dynamics CRM?

MSDN 上有一個示例。

該示例的參數比上面的代碼多得多,這可能是問題的原因。

示例:創建和檢索實體關系

CreateOneToManyRequest createOneToManyRelationshipRequest =
    new CreateOneToManyRequest
{
    OneToManyRelationship =
    new OneToManyRelationshipMetadata
    {
        ReferencedEntity = "account",
        ReferencingEntity = "campaign",
        SchemaName = "new_account_campaign",
        AssociatedMenuConfiguration = new AssociatedMenuConfiguration
        {
            Behavior = AssociatedMenuBehavior.UseLabel,
            Group = AssociatedMenuGroup.Details,
            Label = new Label("Account", 1033),
            Order = 10000
        },
        CascadeConfiguration = new CascadeConfiguration
        {
            Assign = CascadeType.NoCascade,
            Delete = CascadeType.RemoveLink,
            Merge = CascadeType.NoCascade,
            Reparent = CascadeType.NoCascade,
            Share = CascadeType.NoCascade,
            Unshare = CascadeType.NoCascade
        }
    },
    Lookup = new LookupAttributeMetadata
    {
        SchemaName = "new_parent_accountid",
        DisplayName = new Label("Account Lookup", 1033),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("Sample Lookup", 1033)
    }
};

為什么 Dynamics 社區如此迅速地告訴人們他們不應該做某事? 可能有一個很好的理由吧? 答案在 CRM 2015 SDK 中。 查找名為 WorkWithRelationships.cs 的類。

無論如何,這是為了后代。

var createOneToManyRelationshipRequest = new CreateOneToManyRequest {
OneToManyRelationship = new OneToManyRelationshipMetadata
    {
        ReferencedEntity = "account",
        ReferencingEntity = "campaign",
        SchemaName = "new_account_campaign",
        AssociatedMenuConfiguration = new AssociatedMenuConfiguration
        {
            Behavior = AssociatedMenuBehavior.UseLabel,
            Group = AssociatedMenuGroup.Details,
            Label = new Label("Account", 1033),
            Order = 10000
        },
        CascadeConfiguration = new CascadeConfiguration
        {
            Assign = CascadeType.NoCascade,
            Delete = CascadeType.RemoveLink,
            Merge = CascadeType.NoCascade,
            Reparent = CascadeType.NoCascade,
            Share = CascadeType.NoCascade,
            Unshare = CascadeType.NoCascade
        }
    },
Lookup = new LookupAttributeMetadata
    {
        SchemaName = "new_parent_accountid",
        DisplayName = new Label("Account Lookup", 1033),
        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
        Description = new Label("Sample Lookup", 1033)
    }
};

var createOneToManyRelationshipResponse = (CreateOneToManyResponse)_serviceProxy.Execute(
createOneToManyRelationshipRequest);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM