Locking mechanism in MS CRM

When CRM is interacting with SQL server what exactly happening in terms of locking at database?..., Here I am trying to articulate the locking mechanism at my best.

When CRM trying to interface with SQL server, SQL server determines which locks it should be apply against a record or table.




  1. If CRM is trying to read a record, SQL server applies Read lock on that record.
  2. If CRM is trying to read multiple of records, SQL server decides whether it should apply Read lock on entire table or respective records
  3. If CRM is creating a record, SQL server applies Write lock on that record.
  4. If CRM is updating a record, CRM will applies write lock on that record.
  5. There may be scenarios SQL server does not apply any locks.
CRM executes all the request under a single transaction each time it is hitting database, SQL server holds the lock until transaction completed. Once the transaction is completed SQL server will release the lock on that record or transaction.

Below scenario explains how the system reacts when multiple of users updating the same record at same time.

























When first transaction gets lock and started it execution, second transaction will be blocked until it gets lock on that record i.e. blocked until first transaction complete.


Sometimes blocking may cause timeout issue when the multiple request executes parallel. The first request can easily lock the record and complete it requests, but the second request should wait until the first request release its lock. Similarly, thirst request should also wait until first and second requests to complete. The more requests there are, the longer blocking will occur. If there are enough requests, and each request takes long enough, this can push the later requests to the point that they time out, even though individually they may complete correctly.




You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015


IME Mode in MS CRM

using Alias in MS CRM

When we are retrieving linked entity related information using FetchXML or Query expression we are using alias attribute to identify the linked entity attributes. Alias name is prefixed to all linked entity attributes.

Below code snippet will give more information on how to use alias in FetchXML.





string fetchXML = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
                                  <entity name='contact'>
                                    <attribute name='fullname' />
                                    <attribute name='telephone1' />
                                    <attribute name='contactid' />
                                    <attribute name='middlename' />
                                    <attribute name='lastname' />
                                    <attribute name='firstname' />
                                    <order attribute='fullname' descending='false' />
                                    <link-entity name='account' from='accountid' to='parentcustomerid' visible='false' link-type='outer' alias='AliasAccountName'>
                                      <attribute name='donotphone' />
                                      <attribute name='accountclassificationcode' />
                                      <attribute name='createdon' />
                                      <attribute name='crisp_balance' />
                                    </link-entity>
                                  </entity>
                                </fetch>
                                ";
 FetchExpression fetchExpression = new FetchExpression(fetchXML);
 EntityCollection fetchCollection = service.RetrieveMultiple(fetchExpression);

Here “service” is an organization service. Click here for more information on how to create organization service

After you run above fetchxml, the way we are reading account related attributes are bit different than customer related attributes.

Reading alias values for different datatypes:

OptionSet Value:

int aliasOptionsetValue = ((OptionSetValue)((AliasedValue)fetchCollection.Entities[0].Attributes["AliasAccountName .new_status"]).Value).Value;

Lookup:

Guid aliasstateGuid = ((EntityReference)fetchCollection.Entities[0].Attributes["AliasAccountName.crisp_state"]).Id;

string aliasstateName = ((EntityReference)fetchCollection.Entities[0].Attributes["AliasAccountName.crisp_state"]).Name

Money:

decimal aliasamt = ((Money)fetchCollection.Entities[0].Attributes["AliasAccountName.new_balance"]).Value;

Boolean:

bool aliasisactive = Convert.ToBoolean(fetchCollection.Entities[0].Attributes["AliasAccountName.new_isactive"]);

String:

string aliasString = ((AliasedValue)fetchCollection.Entities[0].Attributes["AliasAccountName.new_name"]).Value.ToString();





You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015


IME Mode in MS CRM

Retrieve all entities and attributes metadata in MS CRM

             
Below code snippet will retrieve all entities metadata which includes it's attributes metadata as well.


              RetrieveAllEntitiesRequest metaDataRequest = new RetrieveAllEntitiesRequest();
                RetrieveAllEntitiesResponse metaDataResponse = new RetrieveAllEntitiesResponse();
                metaDataRequest.EntityFilters = EntityFilters.All;

                // Execute the request.

                metaDataResponse = (RetrieveAllEntitiesResponse)service.Execute(metaDataRequest);

              List<EntityMetadata>   entities = metaDataResponse.EntityMetadata.ToList();




Note: "service" is nothing but an organization service you are going to create and you need to include below namespaces...

using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;



You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

Can we register image to custom action in MS CRM?

Answer is No. we can not register images to actions. We can only register images to pre-defined messages like Create, Update, Delete etc.



If you are looking for any attribute values through images, the only options are passing that attribute value as Input parameter or you can write down a fetch xml or Query expression to retrieve those values.




You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Ticker Symbol Field in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015

IME Mode in MS CRM

Get or Set values of all data types using javascript in MS CRM




Single Line of Text or Multi Line of Text:

Set:

Xrm.Page.getAttribute("attribute logical name").setValue("Test");

Get:

Xrm.Page.getAttribute("attribute logical name").getValue();


Two Options:

Set:

Xrm.Page.getAttribute("attribute logical name").setValue(1);

Two options will accept either 1 or 0.

Get:

Xrm.Page.getAttribute("attribute logical name").getValue();

Above code snippet will return “true” in case set value is “1” and “false” if set value is “0”

Xrm.Page.getAttribute("attribute logical name ").getText();

This code snippet will returns the text we have selected.

OptionSet:

Set:

Xrm.Page.getAttribute("attribute logical name").setValue(1);

Get:

Xrm.Page.getAttribute("attribute logical name").getValue();

Above code snippet will return the selected option value.

Xrm.Page.getAttribute("attribute logical name ").getText();

Above code snippet will returns the text of option we have selected.

DateTime:

Set:

Xrm.Page.getAttribute("attribute logical name ").setValue(new Date("12-31-2014"));

Get:

Xrm.Page.getAttribute("attribute logical name ").getValue();


Lookup:

Set:

Xrm.Page.getAttribute("lookupname").setValue([{ id: "record Guid", name: "record name (Optional)", entityType: "entity logical name" }]);


Get:

var lookupVar = Xrm.Page.getAttribute("attribute logical name").getValue();

var ID= lookupVar[0].id;

var Name= lookupVar[0].name;

var LogicalName= lookupVar[0].entityType;


Currency or Decimal:

Set:

Xrm.Page.getAttribute("attribute logical name").setValue("100.00");

Get:

Xrm.Page.getAttribute("attribute logical name").getValue();

Retrieve all attributes using FetchXML in MS CRM




Below code snippets gives an example on how to retrieve all the attributes from an entity using fetch xml.

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='1'>
  <entity name='new_account'>
    <all-attributes />
    <order attribute='createdon' descending='true' />
    <filter type='and'>
      <condition attribute='new_name' operator='eq' value='Test' />
    </filter>
  </entity>

</fetch>

<all-attributes />  will fetch you all attributes in fetch XML.








Ticker Symbol Field in MS CRM




Ticker Symbol is the new feature we are having in MS CRM 2015. This is very useful when we want to navigate the link to respective stocks.


Ticker Symbol:   This creates a stock ticker symbol in all capital letters. Click the symbol to open information about the stock in the user's default browser. By default, the MSN website opens.


Below is the small screen I have developed, and entered Ticker Symbol as “GE”. When I click on this link, it will navigate you to second screen which will have all stock’s related information of GE
















































You may like below posts

Improving MS CRM Performance

Performance Center in MS CRM 2013

date and time field behavior in MS CRM

Upsert in MSCRM

Locking mechanism in MS CRM

Themes in MS CRM

Enable Tracing in MS CRM

Calculated Field in Dynamics CRM 2015


IME Mode in MS CRM

Featured Post

Improving MS CRM Performance

Performance on MS CRM is always a crucial thing and we may follow different ways to achieve the performance thing. Below is the one more a...