1
votes

I need to push changes from a SQL server database to CRM. There are two tables on the SQL side:

Transfer

  • TransferID (sequential)
  • Entity (string, the SQL table name)
  • PKOfEntity (int, also from the table)
  • Action (create, update, destroy)

TransferField

  • FieldID (sequential)
  • TransferID (foreign key)
  • FieldName (string)
  • FieldValue (string)

Now, I need to get these changes into the CRM. I have a mapping of SQL tables to CRM entities, and one of SQL columns to CRM attributes. I do not, however, have a mapping of CRM attributes to CRM types on hand.

I'm using the Microsoft.Xrm.Sdk.Client.OrganizationServiceContext object. Its SetAttributeValue method takes an object, but it doesn't do any conversions; an int field requires passing in an int, and so on. Now, I would really, really, really like to just be able to pass in the field names and values dynamically as strings in one simple foreach, rather than manually checking for and setting dozens of attributes for dozens of models. Is there a reasonable way of doing this?

2

2 Answers

1
votes

I have it working. For each type of entity I come across, I get the entity metadata from the CRM, and then build a Dictionary from attribute names to AttributeTypeCodes. I have a function that switches on the type code and returns the correct type of object.

0
votes

This sounds like an ideal situation for a csv/xml data import project where the Import.ModeCode is set to ImportModeCode.Update. Check out the below links for more detail.