Friday, November 21, 2008

Retrieve Dynamic Record

public DynamicEntity retrieveDynamicEntity(Guid entityID, string entityName)
{
try
{
TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();

// Set the properties of the target.
targetRetrieve.EntityName = entityName;
targetRetrieve.EntityId = entityID;

// Create the request object.
RetrieveRequest retrieve = new RetrieveRequest();

// Set the properties of the request object.
retrieve.Target = targetRetrieve;
retrieve.ColumnSet = new AllColumns();

// Indicate that the BusinessEntity should be retrieved as a DynamicEntity.
retrieve.ReturnDynamicEntities = true;

// Execute the request.
RetrieveResponse retrieved = (RetrieveResponse)service.Execute(retrieve);

// Extract the DynamicEntity from the request.
DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntity;
}
catch (Exception e)
{
return null;
}
}

No comments: