2
votes

I am about to migrate a Dynamics CRM 2011 On Premise instance to Dynamics CRM 2015 Online.

I'm using the current Dynamics CRM SDK (current Version 7.1) and have managed to migrate the custom attributes, except the Virtual and Lookup ones, which can't be created via CreateAttributeRequest.

Now next, I need to migrate all the relationships. So far I've been able to get the necessary OneToManyRelationshipMetadata and ManyToManyRelationshipMetadata. However, for OneToManyRelationshipMetadata I need to pass a LookupAttributeMetadata to the 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"
    }
}

However, I get the exception that attribute new_topicid doesn't exist. That may make sense, since I had to skip it during Attribute creation earlier (since it can't be created through CreateAttributeRequest).

Is there any other way how I can migrate the LookupAttributeMetadata or OneToManyRelationshipMetadata/ManyToManyRelationshipMetadata to Dynamics CRM online?

2
Is there a particular reason you are not using a CRM solution for this?James Wood
The basic idea was that once the program is coded it would be a 1-click migration solution as in "Create an Organization, run the program and when it's done you got an exact copy of the originating organization". But migrating customizations seems like a pain. Migrating data itself is rather easy, once you've done the necessary mappings and migration order of the entitiesTseng
You are probably better off looking at programmatically exporting and importing a solution.James Wood

2 Answers

2
votes

There is a sample on the MSDN for this.

The sample has significantly more parameters than your code above which is probably the cause of the problem.

Sample: Create and retrieve entity relationships

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)
    }
};
1
votes

Why is the Dynamics community so quick to tell people they should not be doing something? There may be a good reason right? The answer is in the CRM 2015 SDK. Look for a class called WorkWithRelationships.cs.

Here it is anyway for posterity.

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);