Import/Export NN relationships fails

Topics: Bug
Dec 15, 2014 at 2:08 PM
We have tried to export NN relationships from CRM 2011.
The software tries to do the job ("Exporting many to many relationship Records .."), but the loop doesn't end at all.
In meantime the size of the file jumps in every few seconds between 0 and 20 kB. After opening the file in "read mode" we noticed that there are 0 ... 250 lines.

For now we have two questions open:
1) Why does the software never stops?
2) Can the software export more than 250 lines?

Dec 16, 2014 at 9:47 AM

There was two bugs that make the tool doesn't work as expected if there is more than 250 relationship records.

It will be fixed in the next release.

If you need a fixed version sooner, send me a private message
Jan 14, 2015 at 9:32 AM

I found bug in Import/Export NN relationships module.
If I have N:N relationship between same entity (Product -> Product), result is fail.

I found that a problem is in method "private void cbbRelationship_SelectedIndexChanged(object sender, EventArgs e)" in finding metadata for second entity:

cbbSecondEntity.Items.Add(new EntityInfo
    Metadata = emds.First(ent => 
            (ent.LogicalName == rel.Entity1LogicalName && rel.Entity1LogicalName != ((EntityInfo)cbbFirstEntity.SelectedItem).Metadata.LogicalName)
            || (ent.LogicalName == rel.Entity2LogicalName && rel.Entity2LogicalName != ((EntityInfo)cbbFirstEntity.SelectedItem).Metadata.LogicalName)
            || (ent.LogicalName == rel.Entity1LogicalName && rel.Entity1LogicalName == rel.Entity2LogicalName))

Jan 14, 2015 at 12:40 PM
Thanks for reporting!

I will fix this as soon as possible
Jan 14, 2015 at 4:02 PM
Edited Jan 14, 2015 at 4:03 PM
Thanks, but I found 1 very important bug!
In this extension is using for represent name of relationship "IntersectEntityName" field and It's not correct.
We should use SchemaName for this.

We have case when name of relationship was with upper chars and It was a problem, because for AssociateRequest we have to use SchemaName of relationship.

I fixed this mistake in methods:
  • [MainControl.cs] void tsbImportNN_Click(object sender, EventArgs e)
        var settings = new ImportFileSettings
            FirstEntity = ((EntityInfo)cbbFirstEntity.SelectedItem).Metadata.LogicalName,
            FirstAttributeIsGuid = rdbFirstGuid.Checked,
            FirstAttributeName = ((AttributeInfo)cbbFirstEntityAttribute.SelectedItem).Metadata.LogicalName,
            Relationship = ((RelationshipInfo)cbbRelationship.SelectedItem).Metadata.SchemaName,
            SecondEntity = ((EntityInfo)cbbSecondEntity.SelectedItem).Metadata.LogicalName,
            SecondAttributeIsGuid = rdbSecondGuid.Checked,
            SecondAttributeName = ((AttributeInfo)cbbSecondEntityAttribute.SelectedItem).Metadata.LogicalName,
  • [RelationshipInfo.cs] override string ToString()
        return string.Format("{0} ({1} - {2})",
And last bug I am not sure, but If I did debug (Windows 7 Pro SP1) I have cross-thread exceptions in these methods:
  • [RelationshipInfo.cs] void ie_RaiseSuccess(object sender, ResultEventArgs e)
  • [RelationshipInfo.cs] void ie_RaiseError(object sender, ResultEventArgs e)
I added condition for InvokeRequired to these methods:
void ie_RaiseSuccess(object sender, ResultEventArgs e)
        if (listLog.InvokeRequired)
                ie_RaiseSuccess(sender, e);

        listLog.Items.Add(string.Format("Line '{0}' : Success!", e.LineNumber));

    void ie_RaiseError(object sender, ResultEventArgs e)
        if (listLog.InvokeRequired)
            this.Invoke((MethodInvoker) delegate
                ie_RaiseError(sender, e);

        listLog.Items.Add(string.Format("Line '{0}' : Error! {1}", e.LineNumber, e.Message));

Jan 17, 2015 at 10:14 AM
Thank you for all these information.

Except the last "bug" which occurs only when debugging, I'll fix everything for the next release.

The IntersectEntityName use came from a previous bug. Someone ask me to use this property instead SchemaName. There is maybe a specific behavior for some relationships. I will reuse SchemaName and we will see if someone report again the bug?
Marked as answer by tanguy92 on 1/17/2015 at 2:14 AM
Jan 17, 2015 at 10:27 AM
OK, sorry for last bug :)

About name of relationship you can look up original documentation from Microsoft:
For a many-to-many relationship, this message creates a record in the intersect table for the relationship, which contains the ID of both the referenced and referencing records. The intersect table name is defined in the IntersectEntityName property for the relationship. You need this when you query for the records. However, you need the relationship name to set the Relationship property. This name is defined in the SchemaName property for the relationship. >