More About This Website

All information is provided "AS IS" with no warranties, and confers no rights

Login
Powered by Squarespace
« Thinking Multi Tenant With CRM 4 (Titan) | Main | CRM Titan FAQ Updates »
Friday
Oct052007

Create, Get, Delete Custom Entity via API

One of the new features of CRM 4 (Titan) is the ability to not only read from the platform Metadata but to be able to modify it though the API as well. 

If you are familiar with CRM3, you were only able to do these type of changes though the web client, or by importing existing customization files.

There's lots of things you can do with this capability, but for this post, I'm just going to use the API to create a custom entity, read it back and finally delete it to cleanup.

First an up front disclaimer, the SDK docs are still a little thin here so take the following example with a grain of salt, and use it to understand the concept not as a reference for all the features.

To Create the Custom Entity, we need to do a CreateEntityRequest

image            

Before you call the Execute there's one more required step, you must setup the Primary Attribute - in this case I'm going to use Name as the primary attribute.

   image

Note: In CTP3 if you do not set the MaxLength property you will get an Unexpected Exception from the API

And finally, we actually call the Execute method on the Metadata service to perform the request

   image

Now at this point we could jump over to the web client and check the list of custom entities and we should see the new entity on the list.  The other thing we could do is use the RetreiveEntityRequest and do the same check using the API

image

Finally, using the API, I will just delete the new custom entity I just created

image

One thing you might notice above is the fact that when I set the DisplayName and Description Properties on both the Entity and the Attribute I did it by calling a helper method called CreateSingleCRMLabel.  Those properties are of type CrmLabel which is designed to support the multi language aspects of CRM 4 and allow you to set one or more language strings for each of the properties.  In a future post, I will elaborate more on how you can use the CrmLabel but for now here's a simple code snippet for the helper method

image

So with the ability to do Metadata modifications using the API you can now can do things like automate the creation of your custom schema as part of your install program. It also makes it so in the uninstall routine you can remove attributes or entities if you want to completely remove your solution from a schema.  In a future blog post I will look at how you can surgically add custom attributes one at a time because that is real useful when your adding your solution to an existing entity.

EmailEmail Article to Friend

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.