12.04.09
CRM 4 vb.net example of dynamic entity retrieval
‘This was used in a plugin hence the “ICrmService” as a parameter in the function.
 ‘Otherwise, “CrmService” would have been used instead.Â
Private Function GetDynamicEntity(ByVal entityName As String, ByVal entityID As Guid, ByVal service As ICrmService, ByVal colsArray() As String) As DynamicEntity
‘ Create the column set object that indicates the fields to be retrieved.Â
Dim cols As New ColumnSet()
‘ Set the properties of the column set with the column array passed in.
cols.Attributes.AddRange(colsArray)
‘ Create the request object.Â
Dim retrieve As New RetrieveRequest()
Dim target As New TargetRetrieveDynamic()
‘ Set the properties of the target object.Â
‘ EntityId is the GUID of the record being retrieved.
target.EntityId = entityID
target.EntityName = entityName
‘ Set the properties of the request object.
retrieve.Target = target
retrieve.ColumnSet = cols ‘*** retrieves only the attributes specified in the array passed in for the target (entity).Â
‘retrieve.ColumnSet = New AllColumns ‘*** retrieves all attribues for the target (entity).
retrieve.ReturnDynamicEntities =True
 ‘ Execute the request.Â
Dim retrieved As RetrieveResponse = CType(service.Execute(retrieve), RetrieveResponse)
Return CType(retrieved.BusinessEntity, DynamicEntity)
End Function
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
Â
target.EntityName = entityName
Â
Â
retrieve.ColumnSet = cols