Monday, April 2, 2012

Create a New Entity in Microsoft Dynamics CRM 2011 Using VB.NET

This illustration will show you how to create a new entity in Microsoft Dynamics CRM 2011 using VB.NET to invoke CreateEntityRequest.

Ok, here is what the code looks like once your service is instantiated!


Dim attribute As New StringAttributeMetadata
attribute.SchemaName = "new_stringattribute"
attribute.DisplayName = New Label("sample string  attribute", 1033)
attribute.RequiredLevel = New AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None)
attribute.Description = New Label("string attribute", 1033)
attribute.MaxLength = 100

Dim entity As New EntityMetadata
entity.SchemaName = "new_vbtest"
entity.DisplayName = New Label("vbtest", 1033)
entity.DisplayCollectionName = New Label("new vbtest entity", 1033)
entity.Description = New Label("our spiffy new entity we made in that doesn't really do anything", 1033)
entity.OwnershipType = OwnershipTypes.OrganizationOwned
entity.IsActivity = False

Dim req As New CreateEntityRequest
req.Entity = entity
req.PrimaryAttribute = attribute
Dim resp As CreateEntityResponse = DirectCast(service.Execute(req), CreateEntityResponse)

Thats all there is to it!

No comments:

Post a Comment