Thursday, January 20, 2011

Using CRM's TargetRetrieveDynamic to retrieve a DynamicEntity via Guid

This is a snippet from the SDK example: <sdk loction>\sdk\server\reference\cs\crmservice\dynamicentityretrieve.cs

 

            // Create the retrieve target.

            TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();

 

            // Set the properties of the target.

            targetRetrieve.EntityName = EntityName.contact.ToString();

            targetRetrieve.EntityId = created.id;

 

            // 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;

 

No comments: