8

MS CRM 2015 allows you to specify an attribute mapping on a relationship between entities. E.g. for the "contact_customer_accounts" relation shown below, it defines which attributes from Account should be copied over to the Contact when adding a new Contact via the Account's "related contacts" view.

However, when I change such a mapping (and publish all customizations), it doesn't get exported as part of my solution (or the default solution, for that matter). When I compare the customizations.xml files before and after such a change in mapping, they are (for the relevant parts) exactly the same - this information just doesn't seem part of the export?

I also found the Customization solutions file schema, and it doesn't seem to mention anything about the attribute mappings either.

I'd think that this information should be part of a solution export - does anybody know why it's not?

enter image description here

Update: I imported my solution (with both Account and Contact) in my organization and published. Then removed half of the mappings from the "contact_customer_accounts" relation and published again. Finally imported the same solution and published again: the removed mappings did not return.

So I think it's safe to say that the solution doesn't contain the mapping information.

Leon Bouquiet
  • 4,159
  • 3
  • 25
  • 36
  • Are both entities in the solution? – James Wood Sep 11 '15 at 21:19
  • @JamesWood: Yes, both Account and Contact are in the solution. – Leon Bouquiet Sep 11 '15 at 21:36
  • If you import the solution into another environment is the change included? – James Wood Sep 12 '15 at 12:04
  • @JamesWood: Good question, see my updated post. – Leon Bouquiet Sep 12 '15 at 20:36
  • 1
    so deleting the existing mappings in your Source environment, then pushing the solution into the target environment did not remove the mappings from the target environment? Is that what you're saying? look in the EntityMaps and EntityRelationships nodes of the customizations.xml for info on the mappings – Joseph Duty Sep 25 '15 at 19:06
  • @JosephDuty: No, there is only one environment, where I manually remove half the mappings and then try to bring them back by importing the customizations, which doesn't happen. Your other remark pointed me to the solution, see below. – Leon Bouquiet Sep 26 '15 at 09:11

2 Answers2

10

I have also seen where you have to have both the relationship, and both fields defined the mapping in the solution in order for the mappings to be exported... So if I have Entity A that has a Mapping to B, for fields A.1 to B.1 and A.2 to B.2, I have to make sure that the relationship, and fields A.1, A.2, B.1 and B.2 have been added to the solution as well, or else they don't get exported.

Update

After some further testing, in order for Lookup Attributes to be included in the Export of a Mapping, the Target Attribute field MUST BE included in the solution!

Daryl
  • 18,592
  • 9
  • 78
  • 145
  • 1
    I'm late to the party, but kudos to Daryl. Spot on! The guy who posted the question and then *sort of* answered it below may have found a way to do it, but it's not the right way. Including target lookup fields in the solution is the right answer. – Tony Oct 11 '18 at 12:52
1

As Joseph Duty pointed out, the attribute mappings are stored in the customizations.xml file under ImportExportXml/EntityMaps (see the Customization solutions file schema on how to use them). However, when the solution is exported, they don't seem to contain any "system" relations, only relations in which at least one entity is a custom entity. So that's probably why my mapping changes didn't end up in the solution export.

The good news is that you can add such a mapping by hand to the customizations.xml file, and when imported, you'll see the mapping appear in all relationships between these entities:

<EntityMaps>
  <EntityMap>
    <EntitySource>account</EntitySource>
    <EntityTarget>contact</EntityTarget>
    <AttributeMaps>
      <AttributeMap>
        <AttributeSource>telephone1</AttributeSource>
        <AttributeTarget>telephone2</AttributeTarget>
      </AttributeMap>
      <AttributeMap>
        <AttributeSource>telephone1</AttributeSource>
        <AttributeTarget>telephone3</AttributeTarget>
      </AttributeMap>
    </AttributeMaps>
  </EntityMap>    

Removing one or more AttributeMap elements from the customizations.xml doesn't cause the corresponding mappings to be removed, but this is regular behavior when working with solutions.

Leon Bouquiet
  • 4,159
  • 3
  • 25
  • 36
  • Glad to be of assistance – Joseph Duty Sep 27 '15 at 02:12
  • 1
    What if you need to export the same solution many times? Will you keep manually adding the mapping? It's not the right way to do it. See Daryl's answer above. It solves the problem permanently. – Tony Oct 11 '18 at 12:53