12.04.09

CRM 4 vb.net example of dynamic entity retrieval

Posted in Uncategorized at 2:51 pm by mmwebesa

‘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



Leave a Comment