Wednesday, December 3, 2014

Strange behaviour of the two options(Boolean) field in CRM2013

Last week, I came across a strange behaviour of the two options field in CRM2013. I am not sure if it is a bug or it is by design.

Scenario

I have a boolean field on an entity. This field is not added to the form. The default value of the field is set to false. When a new record is created in CRM, the integration process copies the record into the external system and updates the boolean field to true in the CRM. This boolean field indicates if the record is copied to the external system or not.

It works perfectly expect in the following scenario.

If the user updates the  record immediately after creating the record without closing the form, CRM will reset the value of the boolean field back to false. According to me, it is a bug. CRM should not pass the un modified fields to the save method.

The following screen shot displays the audit history of the field.

image

Solution

Add the field to the form.

Monday, November 24, 2014

InitializeFromRequest in CRM2013

InitializeFromRequest may be the least used request in the Dynamics CRM. It is available since CRM 4.0. I was talking to some of the guys in my team and most of them have never used this request. It initiates an instance of an entity from an existing entity.

It can be used when there is a 1:N relationship between the entities. It is equivalent of creating a child record from the parent form.

For example there is a 1:N relationship between account and contact. if you create a contact from the contact subgrid from the account form, it will prefill the parentcustomer field and all the fields defined in the relationship mappings.

The following screen shot displays the mappings of 1:N relationship between account and contact.
image
The same functionality can be achieved using InitializeFromRequest. This request returns a InitializeFromResponse. The request does not create a new record but the response can be used to create a new record.
Here is the code.
    // Create the request object
     InitializeFromRequest initialize = new InitializeFromRequest();

     // Set the properties of the request object
     initialize.TargetEntityName = "contact";
     

     // Create the EntityMoniker
     initialize.EntityMoniker = new EntityReference("account", new Guid("8A5D8108-DE3B-E311-9401-00155D1B7B00"));
    
     // fields to initialised from parent entity
     initialize.TargetFieldType = TargetFieldType.All;

     // Execute the request
     InitializeFromResponse initialized =
         (InitializeFromResponse)_serviceProxy.Execute(initialize);

     if (initialized.Entity != null)
     {
         //get entity from the response
         Entity entity = initialized.Entity;

         // set the name for the contact
         entity.Attributes.Add("firstname", "John");
         entity.Attributes.Add("lastname", "Smith");

         //create a new contact
         _serviceProxy.Create(entity);

     }
        
Happy coding..

Saturday, August 9, 2014

Setup and Deployment guide for ‘Performance Toolkit’ for Dynamics CRM 2011

Performance Toolkit for Microsoft Dynamics CRM 2011 is available on ‘Microsoft Pinpoint’. But the hyperlink for ‘setup and deployment’ guide is not working. It always displays the following message.
service unavailable 

I have found an old copy of the guide. You can download the guide from here.

Thanks.