Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

In C# calling "CreateAnnotation", and getting "Failed to attach the file with exception: An item with the same key has already been added."

$
0
0

Hello all, 

I'm writing a tool to parse a large number of backup files from a different CRM (Salesforce) to upload them to the correct records in our Dynamics CRM Online instance.  I have already imported Accounts, Opportunities, Contacts, and Contracts, and I included a new field in each entity that has the old Salesforce ID in it.  I've written a method now that takes a Salesforce ID, and an entity type, and looks up the correct ID from Dynamics CRM.  That's all working.  My next step is trying a test upload of a Note/Annotation.

I'm using the "CreateAnnotation" method from a working CrmServiceClient (I know it's working because that's how I look up the entity ID).  The line of code is...

DynamicsServiceClient.CreateAnnotation(GetEntityString(WhichEntityType), EntityID, theNoteBuilder.GetPropertyDictionary());

  • DynamicsServiceClient is just the instance of CrmServiceClient.
  • GetEntityString just gets me a string like "account" depending on which entity type I'm trying to attach to.
  • EntityID is the ID I found earlier...

And I just figured out what the problem was.  I'll post this anyway in case anyone else has the same problem.  The dictionary I built included the EntityID too because I was trying to do this with the "Create" method first, and I needed the EntityID of the parent entity among the attributes.  When I switched to using "CreateAnnotation", I didn't think of the fact that it requires you to provide the EntityID as one of the parameters, and I was still including it in the dictionary I was building.

So: just make sure you aren't adding the Entity ID twice (the "targetEntityID" parameter in the method)


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>