Saturday, 30 March 2013

Event Execution Pipeline MSCRM




Architecture and Related Components

The following figure illustrates the overall architecture of the Microsoft Dynamics CRM platform with respect to both synchronous and asynchronous event processing.
Event processing architecture
The event execution pipeline processes events either synchronously or asynchronously. The platform core operation and any plug-ins registered for synchronous execution are executed immediately. Synchronous plug-ins that are registered for the event are executed in a well-defined order. Plug-ins registered for asynchronous execution are queued by the Asynchronous Queue Agent and executed at a later time by the asynchronous service.
ImportantImportant
Regardless of whether a plug-in executes synchronously or asynchronously, there is a 2 minute time limit imposed on the execution of a (message) request. If the execution of your plug-in logic exceeds the time limit, a System.TimeoutException is thrown. If a plug-in needs more processing time than the 2 minute time limit, consider using a workflow or other background process to accomplish the intended task.


Pipeline Stages

The event pipeline is divided into multiple stages, of which 4 are available to register custom developed or 3rd party plug-ins. Multiple plug-ins that are registered in each stage can be further be ordered (ranked) within that stage during plug-in registration.

 

Event Stage name Stage number Description
Pre-Event Pre-validation 10 Stage in the pipeline for plug-ins that are to execute before the main system operation. Plug-ins registered in this stage may execute outside the database transaction.
securitySecurity Note
The pre-validation stage occurs prior to security checks being performed to verify the calling or logged on user has the correct permissions to perform the intended operation.

Pre-Event Pre-operation 20 Stage in the pipeline for plug-ins that are to execute before the main system operation. Plug-ins registered in this stage are executed within the database transaction.
Platform Core Operation MainOperation 30 In-transaction main operation of the system, such as create, update, delete, and so on. No custom plug-ins can be registered in this stage. For internal use only.
Post-Event Post-operation 40 Stage in the pipeline for plug-ins which are to execute after the main operation. Plug-ins registered in this stage are executed within the database transaction.
Post-Event Post-operation (Deprecated) 50 Stage in the pipeline for plug-ins which are to execute after the main operation. Plug-ins registered in this stage may execute outside the database transaction. This stage only supports Microsoft Dynamics CRM 4.0 based plug-ins.

Message Processing

Whenever application code or a workflow invokes a Microsoft Dynamics CRM Web service method, a state change in the system occurs that raises an event. The information passed as a parameter to the Web service method is internally packaged up into a OrganizationRequest message and processed by the pipeline. The information in the OrganizationRequest message is passed to the first plug-in registered for that event where it can be read or modified before being passed to the next registered plug-in for that event and so on. Plug-ins receive the message information in the form of context that is passed to their Execute method. The message is also passed to the platform core operation.

Plug-in Registration

Plug-ins can be registered to execute before or after the core platform operation. Pre-event registered plug-ins receive the OrganizationRequest message first and can modify the message information before the message is passed to the core operation. After the core platform operation has completed, the message is then known as the OrganizationResponse. The response is passed to the registered post-event plug-ins. Post-event plug-ins have the opportunity to modify the message before a copy of the response is passed to any registered asynchronous plug-ins. Finally, the response is returned to the application or workflow that invoked the original Web service method call.
Because a single Microsoft Dynamics CRM server can host more than one organization, the execution pipeline is organization specific. There is a virtual pipeline for every organization. Plug-ins registered with the pipeline can only process business data for a single organization. A plug-in that is designed to work with multiple organizations must be registered with each organization's execution pipeline.
noteNote
In Microsoft Dynamics CRM 4.0, there existed a parent and a child pipeline. These pipelines have been consolidated into one pipeline for this release. A pre-event plug-in registered in the parent pipeline of Microsoft Dynamics CRM 4.0 is equivalent to registering in stage 10. A pre-event plug-in registered in the child pipeline of Microsoft Dynamics CRM 4.0 is equivalent to registering in stage 20.


Inclusion in Database Transactions

Plug-ins may or may not execute within the database transaction of the Microsoft Dynamics CRM platform. Whether a plug-in is part of the transaction is dependent on how the message request is processed by the pipeline. You can check if the plug-in is executing in-transaction by reading the IsInTransaction property inherited by IPluginExecutionContext that is passed to the plug-in. If a plug-in is executing in the database transaction and allows an exception to be passed back to the platform, the entire transaction will be rolled back. Stages 20 and 40 are guaranteed to be part of the database transaction while stage 10 and 50 may be part of the transaction.
Any registered plug-in that executes during the database transaction and that passes an exception back to the platform cancels the core operation. This results in a rollback of the core operation. In addition, any pre-event or post event registered plug-ins that have not yet executed and any workflow that is triggered by the same event that the plug-in was registered for will not execute.


Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online support the execution of plug-ins and custom workflow activities in an isolated environment. In this isolated environment, also known as a sandbox, a plug-in or custom activity can make use of the full power of the Microsoft Dynamics CRM SDK to access the organization web service. Access to the file system, system event log, certain network protocols, registry, and more is prevented in the sandbox. However, sandbox plug-ins and custom activities do have access to external endpoints like the Windows Azure cloud.
Microsoft Dynamics CRM collects run-time statistics and monitors plug-ins and custom workflow activities that execute in the sandbox. If the sandbox worker process that hosts this custom code exceeds threshold CPU, memory, or handle limits or is otherwise unresponsive, that process will be killed by the platform. At that point any currently executing plug-in or custom workflow activity in that worker process will fail with exceptions. However, the next time that the plug-in or custom workflow activity is executed it will run normally. There is one worker process per organization so failures in one organization will not affect another organization.
In summary, the sandbox is the recommended execution environment for plug-ins as it is more secure, supports run-time monitoring and statistics reporting, and is supported on all Microsoft Dynamics CRM deployments. In addition, Microsoft Dynamics CRM Online only supports execution of custom workflow activities if they are registered in the sandbox. Support for custom workflow activity execution in the sandbox is new for Microsoft Dynamics CRM 2011 Update Rollup 12 and Microsoft Dynamics CRM December 2012 Service Update.

Trusts

Developers have the option of registering their plug-ins in the sandbox, known as partial trust, or outside the sandbox, known as full trust. Full trust is supported for on-premises and Internet-facing Microsoft Dynamics CRM deployments. For a Microsoft Dynamics CRM Online deployment, plug-ins or custom workflow activities must be registered in the sandbox (partial trust) where they are isolated as previously described.
ImportantImportant
Custom workflow activities and plug-ins that were developed using the Microsoft Dynamics CRM 4.0 SDK are not supported for execution in the sandbox or by Microsoft Dynamics CRM Online.

Run-time Statistics

The Microsoft Dynamics CRM platform collects run-time information about plug-ins and custom workflow activities that execute in the sandbox. This information is stored in the database using PluginTypeStatistic entity records. These records are populated within 30 minutes to one hour after the sandboxed custom code executes. See the PluginTypeStatistic attributes to find out what information is collected. You can retrieve this information by using the retrieve message or method.
Pre and Post Images
Pre and Post images contain snapshots of the primary entity’s attributes before and after the core platform operation. Microsoft Dynamics CRM populates the pre-entity and post-entity images based on the security privileges of the impersonated system user. You can specify to have the platform populate these properties when you register your plug-in. The entity alias value you specify during plug-in registration is used as the key into the image collection. Once your plugin and steps are registered, register new image using the plugin registration tool. You have to make sure to use the same name in the EntityAlias field which you will use to query in the plugin code. For
e.g.: PluginExecutionContext.PreEntityImages.Contains(“PreImageXML”), make sure to use “PreImageXML” as EntityAlias while registering image.
You will need to repeat same steps for post image as well. For best performance, only select attributes which are used in the plugin code to be passed in the pre and post images. Passing all attributes would slow down the plugin execution. There are some events where images are not available. Below is a quick summary of pre and postimage support in CRM 2011.




Thursday, 28 March 2013

Early Bound IN MSCRM2011

Early Bind in CRM 2011


When you're working with Dynamics CRM 2011 and you need to write plug-ins or other kinds of integration with .NET code you should make use of early binding. This gives you a context that contains a typed .NET representation of all your entities, relations...
Account entity = new Account ();
entity ["name"] = "My Account"; //loosely typed, late binding
entity.AccountNumber = "1234"; //strongly typed, early binding
Advantages of Early Binding are
1) You no longer have to work with magic strings when accessing attributes
2) Every property is typed the correct way. No need to cast attributes values anymore.
3) When entities or attributes are removed, renamed ... and you update your context your code   won't    build and you can fix each problem immediately. No more runtime errors.
4) Less bugs
5)  Less manual work
Run the CrmSvcUtil.exe tool, with the Microsoft.Xrm.Client.CodeGeneration extension, to generate your entity classes and service contexts. The following is an example command to create a file called Xrm.cs that points at an instance of Microsoft Dynamics CRM. Note that the Microsoft.Xrm.Client.Code Generation.dll file must be in the same directory as the CrmSvcUtil.exe file, or in the system GAC, when you run this command.
Download the CRM 2011 SDK to get Microsoft.Xrm.Client.CodeGeneration.dll and CrmSvcUtil.exe tool
Here are the steps to create early binding
1)      Open the Command Prompt 
2)      Navigate to the SDK folder \sdk\bin
3)      Run the command given below by changing the server name and organization name to your crm server name and organization name for which you want to create the early binding
CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization,          Microsoft.Xrm.Client.CodeGeneration" /out:Xrm.cs /url:http://CRMSERVERNAME/Organization NAME/XRMServices/2011/Organization.svc /domain:CONTOSO  /username:administrator /password:pass@word1 /namespace:Xrm /serviceContextName:XrmServiceContext
 
It will create a xrm.cs file in your /sdk/bin  folder 

Saturday, 23 March 2013

MS CRM Dynamics Interview Question and updates



MS CRM 2011 Knowledge enhancer

CRM Service of MSCRM? Ans: CRM Service is the main web service and it exposes Six methods such that you can write your code against CRM entities. To perform operation other than the six operations we will have to use the Execute method.

Metadata service of MSCRM. Ans: Dictionary meaning of the word METADATA is data about data and similarly the metadata holds the information about MSCRM means the information about the entity and attribute e.g. Display name, platform name, size of the attribute, datatype of attribute etc. If we want to access any information about any entity (Dynamic or system) we will have to make use of the Metadata service. In the database we can find the metadata table and name of these table begins with keyword Metadata.

Discovery Service? Ans: The Discovery service is a global service that helps the caller to detemine the correct organization and URL. Microsoft CRM server may include several servers. Each server might be dedicated to multiple organization. Each of these servers will have dedicated web-service URL for faster operations. Internally the Microsoft CRM server allocation may change so the discovery service directs the request to its corresponding web-server for further processing.
In short the Discovery service responsibility is to find the ‘CRM Service’ and ‘Metadata Service’ urls.

How to join two table using Query Expression? Ans: Using Linked entity. You should always try to minimize the number of SWS calls that we make in the database. Often during code review it is explored that the number of Microsoft CRM web-service could have been reduced by making use of the Linked-entity concept. So we should always look for the opportunity to minimize the effort.
 Q. Suppose there is a plug-in registered for account entity. When a user submits a request (e.g. account creation etc.) to the web-server then what will happen in the server?
Ans – The plug-in will get loaded into the memory and will perform the operation it is needed to do.
Q. Now what will happen if 100 users will submit the request to the web-server? The plug-in code will get loaded into the memory for 100 times?
Ans – Answer is NO. Noticable point over here is that the Microsoft CRM is a mananged application and runs under .Net framework. So whenever the first request arrives at the web-server the plug-in code is loaded into the memory and will perform its operation and susequently the same plug-in code will serve the process for other user as well. So this way it saves the amount of time required to load the plug-in into the memory. If the plug-in code is not being used for long then the Garbage collector will identify it and will sweep the plug-in out from the memory.
Q. How to add/remove columns in an entity lookup window.
Ans – Go to Settings >> Customization >> Select the entity >> Click ‘Forms and Views in the Left Nav Pane” >> Double click the ‘Entity Lookup View’ >> Dialog box appears that contains the Add/Remove and Sorting options for a lookup view.
Q. How to Debug the java script that we write for some validation on entity pages.
Ans – Following are the steps that are needed to be followed:
1. Enable the Debugging in the Internet Explorer – Goto Tools >> Internet Options (wizard will appear >> Click the ‘Advanced Tab’ >> Under Browsing Section uncheck the ‘Disable script debutting’ checkbox >> Click OK.
2. Edit the java script code of the Entity Page that you want to debug.
3. Put the statement ‘debugger;’ above the line where you want do the debugging. e.g. suppose my java-script show ‘Hello World’ message and i want to debug this then following is the way I am going to add script:
debugger;
alert(‘Hello World’)
4. Save and Publish corresponding customization.
5. Perform the operation that would trigger the java script written by you
6. Debugger dialog box will appear and select appropriate debugger (Visual Studio new or existing instance)
And you may start debugging from the ‘Debugger’ statement of your javasript.
 What is ‘Append’ and ‘Append To’ privilege in MSCRM? Give one example of it?
Ans: ‘Append’ and ‘Append To’ priviledges works together. ‘Append To’ priviledge will allow other entities to get attached with the entity. ‘Append’ priviledge will allow the entity to attach the records to the entity with ‘Append To’ privildege.
Let us understand this with simple example:
Let us say that you want to attach a note to a case then note entity should have ‘Append’ access right and case entity should have ‘Append To’ access right.
Let us take one more example to understand this. Suppose you have two custom entities called ‘TestCustomEntity1′ and ‘TestCustomEntity2′. You want to attach the ‘TestCustomeEntity2′ records to ‘TestCustomEntity1′records. For this you need to have ‘Append’ access right on ‘TestCustomEntity1′ entity and ‘Append To’ access right on ‘TestCustomEntity2′.
Now guess will I be able to attach the records? Answer is “NO” because we need to create a 1:N relationship between ‘TestCustomEntity1′ and ‘TestCustomEntity2′.
Now the user who has above mentioned access right in his security role will only be able to add ‘TestCustomEntity2′ records to ‘TestCustomEntity1′.
Q. How to create a Custom Entity record using SDK?
Ans: Using Dynamic Entity.
Q. How to join two table using Query Expression?
Ans: Using Linked entity. You should always try to minimize the number of SWS calls that we make in the database. Often during code review it is explored that the number of Microsoft CRM web-service could have been reduced by making use of the Linked-entity concept. So we should always look for the opportunity to minimize the effort.
Q. Can we modify the name of Root Business Unit?
Ans: No; We will have to re-install MSCRM.
Q. Suppose if I have 20 user license and I have created 20users. What will happen if I create 21st User?
Ans: The 21st User will get created in MSCRM but that user will be in disabled state.
Q. What are the maximum number of tabs allowed on a Microsoft Dynamics CRM 4.0 form? 
Ans: 8
Q. How to enable/disable the form assistant? How to make sure the form assitant is expanded/cllapsed on a form?
Ans: Navigate to Customization >> Open the Entity >> Open Forms and Views >> Open Form >> Select Form Properties >> Open Display Tab >> Check/Uncheck the “Enable the Form Assistant” and “Expanded by Default”.
The interviewer will always try to figure-out whether one is comfortable with the basic concepts of Microsoft CRM (MS CRM) or not and after that; questions will be asked from your previous experience (if you have any experience in CRM). Those questions will be something like this:
Q. What was you role in the MSCRM implementation project that you have worked on?
You should be honest while giving answer to this question and should give a brief overview of the project and your role. This is very important question because the answer of this question will trigger so many questions. You should highlight the key skills you have; this way you will divert the attention of the interviewer to your key skills and try not to expose the area in which you are less confident.
Q. What was the most challenging task you have faced till now?
Here you should give answer that exhibit your positive attitude . e.g. for a technical consultant it may be something like … “I was new to the support and during this experience i faced challenging issue related to plug-in that improved my debugging skills. Email-to-case plug-in was really difficult as we had to take care of so many conditions. I have learn t one thing during my previous assignment and that is ‘Never give-up’”.
  Q What was the size of the implementation? (i.e. the number of user-licenses)
I hope this post will help you to crack technical interviews on MSCRM. All the best for your interview…
1.1.1        What are plug ins? Have u implemented , developed plug ins?

Deciding when to use a workflow vs. a plug-in is usually a straight forward process. In general, I always recommend using workflow to automate business processes especially if the business process will be later modified/maintained by “business” people (non IT).
However, there are some characteristics that will guide you to use one versus the other that do require you to know a bit more details of the task that you are trying to achieve. For example, if you require performing an action right away, let’s say when a record is updated (synchronous), then you have to use plug-ins because workflows are always asynchronous.
With the CRM 4.0 enhancements to the plug-in and workflow engine as well as the introduction of the web based workflow designer I’ve seen many CRM developers asking the same question: When should I use workflow vs. plug-ins?   The answer is “depends”; the right approach is determined by the characteristics of the task that you are trying to accomplish.  The following matrix gives you my take on this:
Requirement
Plug-in
Workflow
Needs a synchronous action to happen before or after an event occurs
x

The same piece of logic will be executed for different events and possibly on different entities
x
x
The logic needs to be executed while offline
x

Needs elevation of privileges (impersonation)
x

Needs to execute on events other than assign, create, update, setstate
x

The process/logic may take a long time to complete or will be a persistent process (multiple long running steps)

x
Needs an asynchronous action
x
x
End users will need to modify the process logic

x
Child sub processes will be triggered

x
It may also be the case that a combination of both approaches is required; a plug-in can trigger a workflow and a vice versa.  From the above matrix the most decisive factor is whether you need a synchronous action or not; if you do, plug-ins are the way to go, if you don’t then other factors need to be pondered.
       
Q Deployment of CRM, load balancing

CTI integration with CRM
Implementing MS crm in Chinese language
Ms  CRM architecture
Creating  custom workflow in MS CRM
Data migration to MS CRM.
Data synchronization using MS CRM
Outlook client customizations….. shared mail folders etc.
MS Exchange server
MS CRM implementation methodology
Web services of MS CRM
Plug ins
Custom workflows
difference between asynchronous Plugin and workflow ?
How do u implement a solution in foreign language
 Deployment of ms CRM


  why we should deploy plugin in database only
Difference between Quick Campaign and Campaign?
How to schedule am email for specific time for campaign response.
Different service in MS crm ?
 Need To Find Answere
Why We give strong name to plugin ?
 Outlook plugin in  offline mode do we need to add public key token in all outlook client?
Different type of services in MS CRM?
Bugs find in MS CRM 2011 with UR 11 and UR 12
when we select in activities category and sub category filed then we error will occur when user do quick find search in the activities entity.