Search This Blog

Thursday, March 31, 2016

Business Rule in CRM



There are three levels of scope:
ScopeWhere it runs run
EntityAll forms and server
All formsAll forms
Specific formJust that form
 In the top right of the form, use the Scope field to set the scope for the rule. “Entity” scope level is new in CRM 2015. Setting the scope of the business rule at an entity level, forces the business rule executed on both server and clients side.
 For example, on update of an entity record we will set “Description” field mandatory based on some conditions. So in this case we can create Business rule as below:
Business Rules #1
Business Rules #1
  • Server Side Validation
 To test this business rule validation on server side, we create a real time workflow to update this record which should trigger the validation logic:
crm 2015 bpa2
Trigger the workflow from a record and get below error message immediately:
crm 2015 bpa3
The record cannot be saved due to “Business Process Error”:
crm 2015 bpa4
Download log file and we can find the trace details:
 <TraceText>
[Microsoft.Crm.ObjectModel:Microsoft.Crm.ObjectModel.SyncWorkflowExecutionPlugin]
[1769c1b5-1784-e411-80c5-00155d016814: ] Starting sync workflow ‘Test Scope of Business Rule’, Id: 0e69c1b5-1784-e411-80c5-00155d016814
Entering UpdateStep1_step: Sync workflow ‘Test Scope of Business Rule’ terminated with error ‘Attribute ‘new_description’ cannot be NULL’
</TraceText>
 Client Side Validation To test this business rule in client side, we just simply update the record on the form and the error message show up as expected:
crm 2015 bpa5
Thanks to inogic.com site to delivery nice article of business rule. 

Wednesday, March 30, 2016

Managed and Un-Manged solution in CRM

UnManaged Solution
When you import a unmanaged solution all the changes are really changing the default solution, all your changes are copied to the default solution.  Then if you delete the unmanaged solution later the 
changes will remain.


  • In unmanaged solutions we can create components and customise 
  • Unmanaged solutions usually used to export customisations across other organisations. 
  • Unmanaged solution can be deleted however components created in it will not be deleted and will stay as a part of Default solution. If you want to delete we have to do it manually in the default solution
  • UnManaged solution can be overridden by another new version of Unmanaged solution.


Managed Solution
A managed solution is a completed solution in which the solution is prevented from being modified in the environment to which it is imported. A managed solution is intended to be distributed and installed.


  • Managed we can restrict things with the help of "managed properties"

  • Managed solution cannot export
  • Managed solution by deleting it will delete all its components unless referenced from a different solution.
  • Managed solution can be overridden by another new version of managed solution.

ISV
They are used by the Independent Software Vendors (ISV's) who sell a set of IP that is not expected to be changed or modified by the customer purchasing these solutions. They are positioned to be updated or upgraded only by the ISV that sells them.

Is it possible to edit managed solution
Default Behaviour
When you open the CRM default solution and by default it is not possible to edit the  existing field or  form of  the managed solution but we can edit webresource by default.

 But we can add new field or add new webresource in the form of the existing entity.

Over-ride the default behaviour 
We can over-ride the default behaviour of the editing managed solution in the CRM default solution.Give restriction with the help of "Managed Properties"

How to Roll-back solution to a previous customization state in CRM
It is possible only when you are importing solution in managed mode( not in unmanaged mode).

Managed solutions is  able to create layers of customizations. In the unmanaged model, all customizations are at the same layer, so making any customization will overwrite what is currently in the system.

However, managed solutions have the capability to keep track of which customizations belong to which solution. To the end user, only the top layer (latest solution installed) is visible, but under that layer there can be multiple layers of customizations so you can build a solution on top of another solution without mixing up all the changes. You can think of this capability as using reference assemblies in .net. You can develop a solution by referencing an existing managed solution.

The end result is that you will have two solutions (one depends on another) but there can be a clear distinction of which customizations belong to which solution. Solution layering also means that you can revert-back to a previous system state. If you uninstall a solution, all its components will be removed but the customizations from other solutions in a lower layer will surface back.

Example:
Scenario 1:
Import a single managed solution in PROD environment and delete that solution How CRM will work

Step:1 In DEV environment, create a unmanaged solution as KTI_A and  create a new entity as "TestSoln" and export that solution as Managed solution and import to PROD environment as KTI_A.

Step:2 After importing managed solution in PROD environment, new entity "TestSoln" is created.


Step:3 When you delete the KTI_B solution in PROD environment.

Result
Now you will see "TestSoln" created entity is deleted in PROD environment.

Scenario2:
Import a two managed solution in PROD environment and delete the latest solution let see How CRM will work

Step:1 In DEV environment, create a unmanaged solution as KTI_A and  we have an entity as "TestSoln" and export as Managed solution and import to PROD environment as KTI_A.

Step:2 In PROD environment, new entity "TestSoln" is created.


Step:3 In DEV environment, create a another unmanaged solution as KTI_B  and Add new field as "new_karyatestfield001"  in "TestSoln" entity and export as Managed solution and import to PROD environment as KTI_B.

Step:4 In PROD environment, now you can see that entity with that field created. Internally KTI_B solution is sit on top of the KTI_A managed solution.



Step:5 When you delete the KTI_B  solution in PROD environment.


Result
Now you can see only new created field "new_karyatestfield001" is deleted. Entity "TestSoln" is still maintained in the PROD environment.

Because KTI_B  is sit on top of the KTI_A managed solution. 

  • KTI_A solution has new entity created.
  • KTI_B solution has new field created "new_karyatestfield001".


When delete KTI_B solution, KTI_A solution changes is persist and KTI_B solution changes is removed.

When you compare scenario1 and scenario2, usually when you delete the managed solution corresponding entity also hard deleted. But when entity is refered as more than one managed solution. If you delete the one managed solution, old or latest one solution change persist.



Roll-back solution to a previous customization state in CRM

It is possible only when you are importing solution in managed mode( not in unmanaged mode).

Managed solutions is  able to create layers of customizations. In the unmanaged model, all customizations are at the same layer, so making any customization will overwrite what is currently in the system.

However, managed solutions have the capability to keep track of which customizations belong to which solution. To the end user, only the top layer (latest solution installed) is visible, but under that layer there can be multiple layers of customizations so you can build a solution on top of another solution without mixing up all the changes. You can think of this capability as using reference assemblies in .net. You can develop a solution by referencing an existing managed solution.

The end result is that you will have two solutions (one depends on another) but there can be a clear distinction of which customizations belong to which solution. Solution layering also means that you can revert-back to a previous system state. If you uninstall a solution, all its components will be removed but the customizations from other solutions in a lower layer will surface back.

Example:
Scenario 1:
Import a single managed solution in PROD environment and delete that solution How CRM will work

Step:1 In DEV environment, create a unmanaged solution as KTI_A and  create a new entity as "TestSoln" and export that solution as Managed solution and import to PROD environment as KTI_A.

Step:2 After importing managed solution in PROD environment, new entity "TestSoln" is created.


Step:3 When you delete the KTI_B solution in PROD environment.

Result
Now you will see "TestSoln" created entity is deleted in PROD environment.

Scenario2:
Import a two managed solution in PROD environment and delete the latest solution let see How CRM will work

Step:1 In DEV environment, create a unmanaged solution as KTI_A and  we have an entity as "TestSoln" and export as Managed solution and import to PROD environment as KTI_A.

Step:2 In PROD environment, new entity "TestSoln" is created.


Step:3 In DEV environment, create a another unmanaged solution as KTI_B  and Add new field as "new_karyatestfield001"  in "TestSoln" entity and export as Managed solution and import to PROD environment as KTI_B.

Step:4 In PROD environment, now you can see that entity with that field created. Internally KTI_B solution is sit on top of the KTI_A managed solution.



Step:5 When you delete the KTI_B  solution in PROD environment.


Result
Now you can see only new created field "new_karyatestfield001" is deleted. Entity "TestSoln" is still maintained in the PROD environment.

Because KTI_B  is sit on top of the KTI_A managed solution. 

  • KTI_A solution has new entity created.
  • KTI_B solution has new field created "new_karyatestfield001".


When delete KTI_B solution, KTI_A solution changes is persist and KTI_B solution changes is removed.

When you compare scenario1 and scenario2, usually when you delete the managed solution corresponding entity also hard deleted. But when entity is refered as more than one managed solution. If you delete the one managed solution, old or latest one solution change persist.


Is it possible to edit the managed solution in CRM default solution

Default Behaviour
When you open the CRM default solution and by default it is not possible to edit the  existing field or  form of  the managed solution but we can edit webresource by default.

 But we can add new field or add new webresource in the form of the existing entity.

Over-ride the default behaviour 
We can over-ride the default behaviour of the editing managed solution in the CRM default solution.Give restriction with the help of "Managed Properties"

Maximum size of importing solution file in CRM

Maximum size of solution to import

For Microsoft Dynamics CRM Online the maximum size for a solution is 29.296 MB.
For on-premises organizations, the default maximum size for a solution is 6 MB, but this can be increased as needed.

Change the maximum allowed size by editing the <httpRuntime> element in the web.config file for the application. Edit the executionTimeout and maxRequestLength attributes to allow for the necessary size. After you finish installing the solution you can set it to the size you want.

Tuesday, March 22, 2016

Appointments, contacts, and tasks can't be synchronized because the email address of the mailbox is configured with another Microsoft Dynamics CRM organization. The best practice is to overwrite the configuration when you test and enable the mailbox in your primary organization. Also, change the synchronization method for your mailbox in non-primary organizations to None.

To change the primary synchronization organization and overwrite the setting stored in Exchange, click: Settings > Email Configuration > Mailbox > open a mailbox > Test & Enable Mailbox > select Sync items with Exchange from this CRM Organization only, even if Exchanges was set to sync with a different Organization. This will allow server-side synchronization to work for this CRM instance but the other instance would no longer work for synching that mailbox through server-side synchronization. To change the synchronization method for Appointments, Contacts, and Tasks, click: Settings > Email Configuration > Mailbox > open a mailbox > select None for Appointments, Contacts, and Tasks.


Wednesday, March 16, 2016

Executing Messages in a Single Transaction in Dynamics CRM 2015

Executing Messages in a Single Transaction in Dynamics CRM 2015
In CRM 2015, you can now execute multiple CRM requests in a single transaction. This gives developers the ability to easily rollback or cancel transactions if one of the CRM requests within the transaction fail.

We can now use the "ExecuteTransactionRequest" message which will automatically rollback the entire transaction if any of the associated requests fail.

Example:
We are going to create a record in three different entity.

1.Create a instance of sales order,invoice and email
2.Form a create request
{
{
{
{
{
{
{
{
}
}
}
{
}
{
 I have created a plugin which will force the Invoice to fail during creation, so we can see what happens.
The entire transaction rollback no record is created. 

XRM Methods in Date controls,Notification and Enity

Notification
Xrm.Page.getControl(fieldName).setNotification(message)
Xrm.Page.getControl(fieldName).clearNotification()
Date
Xrm.Page.getControl(arg).setShowTime(bool)
Gets a string for the value of the primary attribute of the entity.
Xrm.Page.data.entity.getPrimaryAttributeValue()

Monday, March 14, 2016

Which one fire first Java-script or Business Rule Running Order

JavaScript trigger and then trigger business rule.

Running Order

It’s possible you could have JavaScript and numerous business rules all running against one field, so the order things run can have a dramatic effect on the outcome.


  1. Any system scripts are applied first.
  2. Any logic in custom form scripts is applied.
  3. Logic in business rules is applied.When there are multiple business rules, they are applied in the  order they were activated, from oldest to newest. 

Accessing Parent form control in CRM

Access account form control from address form
parent.window.opener.Xrm.Page.getAttribute('new_nonupdatable').getValue()

window.opener.Xrm.Page.getAttribute('new_nonupdatable').getValue()