Monday, February 16, 2009

Retrieve Dynamic Entity Records Example



DynamicEntity ObjProject = GetDynamicEntity(crmService, "new_timesheet", new Guid("{21CCFA77-FFF8-DD11-AE96-0003FFD751E0}"));


public static DynamicEntity GetDynamicEntity(ICrmService crmService, string strEntityName, Guid EntityGuid)
{
try
            {
#region Retrieve Entity Record Dynamically
// Create the retrieve target.
                TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();
// Set the properties of the target.
                targetRetrieve.EntityName = strEntityName;
targetRetrieve.EntityId = EntityGuid;


// 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)crmService.Execute(retrieve);


// Extract the DynamicEntity from the request.
                DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntity;
return entity;


#endregion
            }
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new System.Exception(ex.Detail.InnerText);
}
catch (Exception ex)
{
throw new System.Exception(ex.Message);
}
}

3 comments:

Sandip R Patel said...

How can we get collection of dynamic entities?

Ranjitsingh Raghuwanshi - MS CRM Techno-Functional Consultant. said...

Sandeep,

http://mscrm-developer.blogspot.com/2009/04/retrieve-multiple-dynamic-entity.html

This is the URL.
Hope it will help you.

Thanks,
Ranjit

Ranjitsingh Raghuwanshi - MS CRM Techno-Functional Consultant. said...

Hi,


Here is the link for "Retrieve Multiple Dynamic Entity Records Example"


http://mscrm-developer.blogspot.com/2009/04/retrieve-multiple-dynamic-entity.html

Thanks,
Ranjit