Connector for Dynamics: ‘Could not find key [ID field] in Dictionary for entity’ when mapping to custom entity in CRM

Using the Connector for Dynamics I was mapping an entity in GP 2010 to a custom entity in CRM 2013. In this case the schema name of my custom CRM entity is ng_courseinvoice (the display name is Course Invoice). When the map is executed, I get the error message below:

Could not find key “ng_courseinvoiceid” in Dictionary<string, object> for entity “ng_courseinvoice”

I fixed this by updating my map and set the Course Invoice field to the CreateGuid() function. This creates a new ID for the entity.

0 Mapping

I have done some testing and there seems to be some smart in the Connector to handle the update case. This means even though you have specified CreateGuid(), the record in CRM will not receive a new ID when it is updated by the Connector as a result of a change in GP.

As a side note, it is important to map the Integration Key field for the destination CRM record. This field is added to the entity by the Connector’s CRM Adapter Configuration Utility. The Connector uses this field to track GP records against CRM records and keep them in sync. You should set this field to an ID field of the source record in GP (I used Sales Invoice Number\Sales Order ID for Sales Invoice for example). Failing to do so will cause the Connector to create a new CRM record for the corresponding GP record for each update in GP.

Lastly, it is interesting to note that The Connector generates C# code to apply the mapping to the record. Below is the generated code to map the main fields of the destination record in CRM. Value for the ng_courseinvoiceid key was only added after I updated my map as above.

private System.Collections.Generic.Dictionary<string, object> _(Microsoft.Dynamics.Integration.Adapters.Gp2010.GPWebService.SalesInvoice source)
        {
            System.Collections.Generic.Dictionary<string, object> _ = new System.Collections.Generic.Dictionary<string, object>();
            _["ng_accountid"] = this.ng_accountid(source);
            _["ng_amount"] = this.ng_amount(source);
            _["ng_courseinvoiceid"] = Microsoft.Dynamics.Integration.Mapping.Helpers.GeneralMappingHelper.CreateGuid();
            _["ng_name"] = ( ((source != null)
            && (source.Key != null)) ? source.Key.Id : default(string) );
            return _;
        }
Advertisements

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.
This entry was posted in CRM, Dynamics Connector, Dynamics GP. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s