Quantcast
Channel: CRM Development 論壇
Viewing all articles
Browse latest Browse all 10280

Relevant columns not being returned when dynamic entity created

$
0
0

Hi,

I'm trying to retrieve a custom entity, and am passing in the relevant column names, but these columns aren't being returned. Also, when I'm trying to update the context.Target, it's not being updated. I can't see what's wrong in my code, as I'm relatively new to CRM.

Here's my code:

   ColumnSet cols = new ColumnSet();
                string[] attributes = new string[2] { "new_coursedate", "new_trainingmoduleid" };
                cols.AddColumns(attributes);

                DynamicEntity course = service.RetrieveEntity("new_course", courseID, cols);

                context.Target().SetLookupProperty("new_trainingmoduleid", "new_trainingmodule", new Guid(course.GetLookupPropertyValue("new_trainingmoduleid").ToString()));
                context.Target().SetDateTimeProperty("new_startdate", course.GetDateTimePropertyValue("new_coursedate").ToDateTime());

I know that servce.RetrieveEntity returns a business entity normally, but there is code there to ensure that a dynamic entity is returned I've made this call before, so I know that should work. Here's the RetrieveEntity code anyway:

public static DynamicEntity RetrieveEntity(this ICrmService service, string entityName, Guid entityGUID, ColumnSetBase cols)
        {
            TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();

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

            targetRetrieve.EntityId = entityGUID;


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

            // Set the properties of the request object.
            retrieve.Target = targetRetrieve;
            
            retrieve.ColumnSet = cols;

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

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

            DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntity;

            return entity;
 
        }

Thanks.


Viewing all articles
Browse latest Browse all 10280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>