Dynamics CRM: Adding custom attributes to Entities and access them from C#

For more info on managing identities in Dynamics CRM, see my presentation to the MIM Usergroup

I want to add a couple of new custom attributes to the Account and Contact entities. I want the attributes to start with a prefix of “tlk”. I also want to be able to access these attributes from C#

Add “tlk” prefix to the attributes

OOB, Dynamics will a prefix of “new” to any custom attribute. In other to specify your own prefix, do this

1. Create a new Publisher:

a. Navigate to Settings > Customizations, and select Publishers from the list.

b. Click the New button.

c. Provide a display name [TLKPublisher], and specify the prefix [tlk] you would like to use. Note that the Option Value Prefix number will be generated automatically.

d. Click Save and Close.

2. Create a new Solution:

a. Navigate to Settings > Solutions, and click the New button.

b. Provide values for Display Name [TLKPublisher] and Version [1].

c. In the Publisher lookup field, select the publisher you created in step 1 above.

d. Click Save and Close.

3. Add the entities to the solution that you want to add custom attributes to using the new prefix:

a. Open the solution from step 2, and click the Add Existing button.

b. Select the entities [Account and Contact] you would like to include, and click OK.

c. Expand Entities, expand the entity you want to modify, and click Fields.

d. Click New. You will notice here that your new prefix is now being used.

e. Create your custom fields and click Save and Close.

f. Click Save and Close to save the Solution. Note that you may need to click the Information tab in the upper-left corner so the Save and Close button becomes visible.

4. Publish customizations by going to Settings > Solutions, and click Publish All Customizations.

Generate updated metadata – Early bound classes

  1. Download the latest CRM SDK
  2. Open a command prompt, cd to the location of the bin directory. For me

“cd C:\Users\tlkfimportalserv\Documents\CRMSdk2\SDK\Bin”

  1. Select
  • A location to store the generated file.
  • A file name [TLK.XRM.cs]
  • CRM Soap Webservice url
  • CRM SysAdmin account and Password
  • While you can add a namespace, I prefer not to, makes it easier for me manage
  1. Run the following command

CrmSvcUtil.exe /url:http://MyCRMServerName:5555/TLKCRM/XRMServices/2011/Organization.svc /out:C:\Documents\TLK.XRM.cs /username:”tlkenterprise\mycrmadmin1″ /password:”MyPassword”  /serviceContextName:ServiceContext

Add generated metadata to C#

  1. Copy the TLK.XRM.cs to the CRM solution.
  2. Open your CRM solution in VStudio, click add existing item, select the TLK.XRM.cs.
  3. If you have the default generated metadata cs file, exclude it from your CRM solution.

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