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 PowerShell.
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 .
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
- Download the latest CRM SDK
- Open a command prompt, cd to the location of the bin directory. For me
- A location to store the generated file.
- A file name [TLK.XRM.cs]
- CRM Soap Webservice url
- CRM SysAdmin account and Password
- Run the following command
CrmSvcUtil.exe /url:http://MyCRMServerName:5555/TLKCRM/XRMServices/2011/Organization.svc /out:C:\Users\tlkfimportalserv\Documents\HomeInstead\TLK.XRM.cs /username:”tlkenterprise\mycrmadmin1″ /password:”MyPassword” /serviceContextName:ServiceContext
Compile a DLL of the cs file
- Open new class library project in Visual Studio. Name it TLK.XRM
- Include the TLK.XRM.cs in the solution. Remove the default cs.
- Add reference to System.Runtime and Microsoft.Xrm.Sdk.dll
- Compile to form TLK.XRM.dll
Add generated metadata to PowerShell
- Copy the TLK.XRM.dll to suitable location.
- Add the reference at the top of the PowerShell file
Add-Type -Path “C:\dynamics\TLK.XRM.dll”