CRM 4 – error creating dynamic entity, check the property case

I had a frustrating error today whilst trying to create a DynamicEntity in a web service.

For some reason the code was erroring but it wasn’t giving me much of an error message.

in the end it was because the of the string property was slightly mispelt

I had this


which should have been all lower case



very frustrating indeed.  So if you want to see an example of creating a dynamic entity here you go


         static string nameField = "new_name";
         static string emailAddress = "new_emailaddress";
         static string code = "new_code";
         static string userID = "new_userid";
         static string jobTitle = "new_jobtitle";
         static string commision = "new_commision";
         static string phoneNumber = "new_phonenumber";
         static string salesPersonEntityName = "new_salesperson";

     /// <summary>
        /// Creates a new salesperson
        /// </summary>
        /// <param name="crmService"></param>
        /// <param name="salesPerson"></param>
        /// <returns></returns>
        public Guid createSalesperson(CrmServiceWrapper crmService, Salesperson salesPerson)
            Guid salespersonID = new Guid();
            if (salesPerson != null)
                try {

                    // Create the DynamicEntity object.
                    DynamicEntity salesPersonEntity = new DynamicEntity();
                    // Set the name of the entity type.
                    salesPersonEntity.Name = PluginQuery.salesPersonEntityName;
                    // Set the properties of the contact using property objects.
                    StringProperty salespersonCode = new StringProperty();
                    salespersonCode.Name = PluginQuery.code;
                    salespersonCode.Value = salesPerson.Code;

                    StringProperty salespersonName= new StringProperty();
                    salespersonName.Name = PluginQuery.nameField;
                    salespersonName.Value = salesPerson.Name;

                    StringProperty salespersonPhoneNumber = new StringProperty();
                    salespersonPhoneNumber.Name = PluginQuery.phoneNumber;
                    salespersonPhoneNumber.Value = salesPerson.PhoneNumber;

                    StringProperty salespersonemailAddress = new StringProperty();
                    salespersonemailAddress.Name = PluginQuery.emailAddress;
                    salespersonemailAddress.Value = salesPerson.EmailAddress;

                    StringProperty salespersonjobTitle = new StringProperty();
                    salespersonjobTitle.Name = PluginQuery.jobTitle;
                    salespersonjobTitle.Value = salesPerson.JobTitle;
                    // Create the target.
                    TargetCreateDynamic targetCreate = new TargetCreateDynamic();
                    targetCreate.Entity = salesPersonEntity;

                    // Create the request object.
                    CreateRequest create = new CreateRequest();

                    // Set the properties of the request object.
                    create.Target = targetCreate;
                    //Property prop = new Property(customernumber);

                    // Execute the request.
                    CreateResponse createResponse = (CreateResponse)crmService.Execute(create);
                    salespersonID =;

                } catch(Exception e){

            //DynamicEntity newAcc = (DynamicEntity)createResponse();
            return salespersonID;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s