Wednesday, 11 September 2013

Create a add-in in for outlook 2007 to append a message on create of activity

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Interop.Outlook;
using System.Windows;
using System.Windows.Forms;
namespace OutlookAddIn1
{
    public partial class ThisAddIn
    {
        Outlook.Inspectors inspectors;
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            inspectors = this.Application.Inspectors;
            inspectors.NewInspector +=
            new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
            this.Application.ItemSend += new ApplicationEvents_11_ItemSendEventHandler(saveEmail);

        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);

        }

        #endregion
        public void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
        {
            Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
            Outlook.TaskItem taskItem = Inspector.CurrentItem as Outlook.TaskItem;
           Outlook.AppointmentItem appItem = Inspector.CurrentItem as Outlook.AppointmentItem;
            DialogResult res = MessageBox.Show("Do you want to create Private Activity ? Press ok  ", "", MessageBoxButtons.OKCancel);


            if (mailItem != null && (res == DialogResult.OK))
            {
                if (mailItem.EntryID == null)
                {
                    mailItem.Subject = "[MNPI ACTIVITY:]";
            

                }

            }
            if (taskItem != null)
            {
                if (taskItem.EntryID == null)
                {

                    taskItem.Subject = "Private Task";

                }

            }
            if (appItem != null)
            {
                if (appItem.EntryID == null)
                {

                    appItem.Subject = "Private Appoinment";

                }

            }


        }

        private void saveEmail(object Item, ref bool Cancel)
        {

        }

    }

}

Sunday, 8 September 2013

Fetch XMl VS Query Expression in Mscrm 2011

When developer want to query in MSCRM 2011 often thinks of Query Expression or Fetch XMl.
A question arises in  developer mind what is the difference and which one is better.
Fetch is a proprietary query language that is used in Microsoft Dynamics CRM. It is based on a schema that describes the capabilities of the language. The FetchXML language supports similar query capabilities as query expression
Using fetch XML one can get in result attribute from related  entity also but not in Query expression. using FetchXML , you can set the Related Entity columns in filter criteria to return the Query Result. FetchXml allows the querying of CRM data using an XML representation.

Querying CRM DB using QueryExpression one cannot able to set Related Entity columns as filter criteria to return the Query Result.

Type of Entity in MSCRM 2011



Types of Entities in CRM:

·         System Entity:System entities are used by Microsoft Dynamics CRM to handle all internal processes, such as workflows and asynchronous jobs. You cannot delete or customize system entities.

·         Business Entity:Business entities are part of the Microsoft Dynamics CRM default installation and they appear in the customization user interface. An account, contact, and letter are examples of business entities

·         Custom Entity: After installation, you can add custom entities to Microsoft Dynamics CRM to address specific business needs of the organization. In a Microsoft Dynamics CRM Solution, you can set business and custom entities and attributes to be either customizable or non-customizable.

Procees to attach the Debugger in MSCRM 2011



Process to attach the debugger while debugging plug-inonline, offline, custom workflow

Plug-in Registration Configuration
Service Process
online
w3wp.exe
offline
Microsoft.Crm.Application.Hoster.exe
asynchronous registered plug-ins (or custom workflow assemblies)
CrmAsyncService.exe
sandbox (isolation mode)
Microsoft.Crm.Sandbox.WorkerProcess.exe

Principal Object Access Table n MSCRM 2011



Principal Object Access Table
POA (principal object access) table is a table for sharing of records. The shared, assigned and re-parented or inherited records are added to this table. Basically if you try to access a record that you do not own the system will check the POA and if the permission is there then you can access the record.
The POA table is used to provide access to specific records for CRM users, and each record in the POA table represents one CRM object that is related to one CRM user. Records created in the POA table come from one of four ways:
• Share reassigned records with original owner: CRM System Settings
 If this is set to Yes, then records would be added to the POA table whenever an assign takes place. These records will have a value in the AccessRightsMask column of the POA table.
• Direct sharing: Actions – Sharing
àWhen users explicitly share a record to another user, a record would be created in the POA table. These records will have a value in the AccessRightsMask column of the POA table.
• Reparent Setting: Relationship Behavior
àEach entity has relationships with other entities (ex. Account to Case). By default, the Reparent option is set to Cascade All. With this setting, sub records would be shared to the owner of the parent record. For example: Let’s say that User1 owns Account1. User2 has access to Account1 and creates a case underneath Account1. With the out of the box Reparent options, a record would be created in the POA table that would give User1 access to the newly created case. These records will have a value in the InheritedAccessRightsMask column of the POA table.
• Indirect Sharing
àWhen sharing occurs through a direct share, assignment, or parenting, if the relationship is set up to cascade the share to child records, additional records will be created in the POA table in order to give proper permissions to the new user for the relevant child records. These records will have a value in the InheritedAccessRightsMask colum of the POA table.

The Reparent setting is what seems to come as a surprise to some customers. Many customers will keep the Reparent setting set to Cascade All. This is a perfectly acceptable setting, but if the majority of your users already have access to the records that are being shared to them through their security role, the records in the POA table may not be providing much of a benefit.

It is possible to change the Reparent setting to Cascade None. In this scenario, records would not be auto-created in the POA table for the owner of the parent record. Building off of the example mentioned above: User1 owns Account1. User2 has access to Account1 and creates a case underneath Account1. With the relationship set to Cascade None, a record would not be created in the POA table for User1.

SSRS Reports in MSCRM 2011



Following are some general questions about SSRS development to see if general working knowledge of SSRS is known.


      Different kinds of SSRS Reports?
 
  • Reports can be categorized into operational and analytical reports. The distinction is based on the source of data and level of analysis facilitated by any particular report. Operational reports are based on OLTP sources and are static reports and Analytical reports are based on OLAP sources and generally facilitate drill-down and drill-through for analysis. Technically, SSRS reports can be categorized into parameterized, linked, snapshot, cached, etc...  

Pre-filtering in SSRS reports:
You can use CRMAF_ prefix or CRM_FilteredEntity parameter in report to enable data pre-filtering. Using pre-filtering concept, you can enable the user to run report only for the selected records in MS CRM.
·         CRMAF_ prefix on filtered views in sql query, makes the report Pre filterable in MSCRM.
·         The CRM_FilteredEntity parameters are used in a query expression to enable data pre-filtering (through Advanced Find) on a filtered view.

Group By and Having function in SQL
Group By clause
Group By is used in conjunction with aggregate functions to collect data across multiple records and group the results by one or more columns.
Example: The below query returns the departments and the number of employees working in the respective departments of the company.
Select departments, count(employees) from company group by departments
SQL aggregate functions return a single value, calculated from values in a column.
Useful aggregate functions:
  • AVG() - Returns the average value
  • COUNT() - Returns the number of rows
  • FIRST() - Returns the first value
  • LAST() - Returns the last value
  • MAX() - Returns the largest value
  • MIN() - Returns the smallest value
  • SUM() - Returns the sum

Having clause:
The SQL HAVING clause is used in combination with the Group By clause. It can be used to filter the records that a SQL GROUP BY returns
Example: The following SQL statement retrieves the employees who have registered more than 10 orders:
SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM (Orders
INNER JOIN Employees
ON Orders.EmployeeID=Employees.EmployeeID)
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 10;
Reports:
The report definition (data and layout) of Microsoft Dynamics CRM reports are contained in an .rdl file, and the contents of the .rdl file conform to the Microsoft SQL Server Report Definition Language Specification.
Microsoft Dynamics CRM provides many out-of-box reports for viewing your business data. You can create custom reports using one of these reports as templates or can create a custom report from scratch.
There are two types of reports in Microsoft Dynamics CRM:
SQL-based
These reports use SQL queries to securely retrieve data for reports from filtered views defined by the system. These are the same reports that have been available for previous versions of Microsoft Dynamics CRM. The default reports that are shipped with Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online are SQL-based reports.
For security reasons, you cannot deploy custom SQL-based reports to Microsoft Dynamics CRM Online.
Fetch-based
These reports are introduced in Microsoft Dynamics CRM 2011 and use FetchXML queries to retrieve data for reports. You can deploy custom fetch-based reports to Microsoft Dynamics CRM Online and to on-premises Microsoft Dynamics CRM 2011. All reports that are created using the Report Wizard in the Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online are Fetch-based reports.
Reports in Microsoft Dynamics CRM Online run in sandbox mode, and this is done by enabling RDL sandboxing in Microsoft SQL Server Reporting Services. As a result, certain features might not be available in Microsoft Dynamics CRM Online. For example, custom code in your report definition will not work.