Tuesday, August 6, 2013

Send email using late binding CRM 2011

You can easily send emails using late binding in CRM 2011 here is the code snippets to send an email.              

WhoAmIRequest systemUserRequest = new WhoAmIRequest();
                WhoAmIResponse systemUserResponse =                    (WhoAmIResponse)serviceProxy.Execute(systemUserRequest);
                Guid _userId = systemUserResponse.UserId;
                Entity Fromparty = new Entity("activityparty");
                Entity Toparty = new Entity("activityparty");
                //set partyid
                //You can refer http://msdn.microsoft.com/en-us/library/gg328549.aspx to get acitivity party entity attribute
                Toparty["partyid"] = new EntityReference("contact", _contactId);
                Fromparty["partyid"] = new EntityReference("systemuser", _userId);
                //create email  and set attributes
                Entity emailCreate = new Entity("email");
                emailCreate["from"] = new Entity[] { Fromparty };
                emailCreate["to"] = new Entity[] { Toparty };
                emailCreate["subject"] = "subject";
                emailCreate["description"] = "EmailBody";
                emailCreate["regardingobjectid"] = new EntityReference("incident", regardindId);
                Guid emailId = serviceProxy.Create(emailCreate);

If you need more information please use comment section :) Thanks

Wednesday, June 12, 2013

Create Dynamic Marketing List in CRM 2011 with C# .Net


If you want to create Dynamic Marketing List in CRM using C# please follow these steps

1. Create your Desired FetchXML using Advance Find in CRM.
2. Download that FetchXML.
3. Use that FetchXML in below code (Just replace " with ' )

your final code looks like

var service = new XrmServiceContext("Xrm");
            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' />
    <order attribute='fullname' descending='false' />
    <filter type='and'>
      <condition attribute='address1_city' operator='eq' value='Florida' />
      <condition attribute='address1_country' operator='like' value='%USA%' />
    </filter>
  </entity>
</fetch>";


            // Create dynamic list. Set the type to true to declare a dynamic list. Set CreatedFromCode to 1 for account member type.
            List dynamicList = new List()
            {
                Type = true, //True for Dynamic List
                ListName = "Dynamic List", //Name of the List
                CreatedFromCode = 2, //1 For Account; 2 For Contact; 3 For Lead
                Query = fetchXml
            };
            Guid _dynamicListId = service.Create(dynamicList);
         
Advantages: Some companies uses marketing list very frequently for example they want different marketing list just with a address1_city change for this purpose we can use .Net to develop such type of Marketing lists easily.

I hope it helps someone :)

Wednesday, June 5, 2013

5 Ways to Import Large Data in Microsoft Dynamics CRM 2011

In this article, I have mentioned possible ways to import data in CRM 2011
There are five possible ways to import data in CRM. If I have missed any, please mention in Comments
  1. CRM 2011 import wizard
  2. Write your own web service using ExecuteMultipleRequest
  3. SSIS Packedge
  4. Use third party integration software like Scribe 
  5. Direct SQL Queries (Unsupported)
Which one is more efficient between these methods depends on your CRM structure, the source of your data, the complexity of the transformation, etc. Every possible solution has some advantages and some disadvantages. 


1.       CRM 2011 import wizard

We can use import wizard to import data in CRM 2011. It is very easy to use. Please follow steps to import data using import wizard.
Download template for the entity that you want to import in CRM

Open the downloaded file

 Fill the excel file with your data

Save the file and from ribbon select import data

This will open import wizard, Browse to your file and select your file as mentioned in below screenshot

Select your desire file and click on submit.

After few times the data will be, upload successfully.

Limitations:

We can’t import non-printable characters using above method.
If we want to Import any entity that has 1:N relationship we need to copy them in one zip file.
If you want to import Unicode data please use XML not Excel.
File size limit is upto 8 MB you can make chunk of data to import them in CRM.

2.       Write your own web service using ExecuteMultipleRequest

Please check my previous blog for this purpose

3.       SSIS Package

We can create SSIS Package to insert data in CRM 2011. Andrii Butenko One of MVP has already write an article on how to integrate CRM 2011 using SSIS. This is really good article so I mentioned it here

4.       Use third party integration software like Scribe.

Many third party tools available that can be used to import data in CRM. Scribe is one of them.

5.       Direct SQL Queries

We can also write SQL queries to insert data in CRM but it is unsupported and not recommended by Microsoft.

Limitations:

Writing direct SQL queries is not supported by Microsoft. One of the biggest disadvantage of using SQL queries is that you bypass Business logic.


I hope it helps someone :)
If you have any suggestion please comment.

Tuesday, May 28, 2013

When to use Email Template and when to Use Mail Merge Template


Mail merge templates are used to send bulk email to multiple users at a same time.
Mail merge templates could be used in following scenarios
     1. Birthday mails.
     2. Appointment letters
     3. Multiple Resignation Letters
Email Templates could be used in following scenarios
     1. New case assigned to a user
     2. New admission application received
     3. Some record needs approval


Here is the table for feature of both templates

Feature
Email Template
Mail Merge Template
Insert merge fields
X
X
Insert custom attribute lookup fields

X
Are available to send in bulk
X
X
Preview before sending in bulk

X
Edit before sending in bulk

X
Place content in the body of an email
X
X
Respect do not contact rules
X
X
Create personal or organization-wide template
X
X
Can be used in workflow
X

Can be created globally for use across multiple entities
X

Can be created for custom entities

X
Requires the Outlook client to create template

X

I hope it helps someone. J

Filter Sub Grid using JavaScript in CRM 2011

Please follow bellow steps to filter sub grid using JavaScript
1. Create FetchXML from Advance find view that you want to set in Sub Grid.
2. Note down the Grid Unique name (We need this in below JavaScript)

Copy the below JavaScript and made changes in BOLD section.

function updateSubGrid() {
    //This will get the related products grid details and store in a variable.
    var relatedAccounts = document.getElementById("YourGridName"); // Your Grid Unique Name
    //Initializing the lookup field to store in an array.
    var lookupfield = new Array;
    //Get the lookup field
    lookupfield = Xrm.Page.getAttribute("contactid").getValue(); // Filter Grid base on the lookup value
    //This will get the lookup field guid if there is value present in the lookup
    if (lookupfield != null) {
        var lookupid = lookupfield[0].id;
    }
    //Else the function will return and no code will be executed.
    else {
        return;
    }
    //This method is to ensure that grid is loaded before processing.
    if (relatedAccounts == null || relatedAccounts.readyState != "complete") {
        //This statement is used to wait for 2 seconds and recall the function until the grid is loaded.
        setTimeout('updateSubGrid()', 2000);
        return;

    }

    //This is the fetch xml code which display all the account associated with the contact.
    //Good Practice is to create FetchXML from Advance Find View and Make formating as mentioned below

    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
    fetchXml += "<entity name='account'>";
    fetchXml += "<attribute name='fullname' />";
    fetchXml += "<attribute name='boardname' />";
    fetchXml += "<attribute name='contactidid' />";
    fetchXml += "<order attribute='appointeestage' descending='false' />";
    fetchXml += "<filter type='and'>";
    fetchXml += "<condition attribute='statecode' operator='eq' value='0' />";
    fetchXml += "<condition attribute='contactid' operator='eq' uitype='contact' value='" + lookupid + "' />";
    fetchXml += "</filter>";
    fetchXml += "</entity>";
    fetchXml += "</fetch>";

    //Setting the fetch xml to the sub grid.
    relatedAccounts.control.setParameter("fetchXml", fetchXml);
    //This statement will refresh the sub grid after making all modifications.
    relatedAccounts.control.refresh();

}

Call updateSubGrid function onload of the form and publish the customization.
I hope it helps someone :)

Wednesday, March 20, 2013

Plugin Walkthrough using Visual studio 2012

Plugin Walkthrough using Visual Studio 2012.

 
Visual studio 2012 makes our life very easy after giving a Dynamics CRM toolkit that could be easily installed and could be used as mentioned here. After installing toolkit Visual studio gives us a new project type of Dynamics CRM. Here are the steps to create and deploy plugin for CRM 2011

Step 1:
Open visual studio click File-> New -> Project and From navigation menu select Dynamics CRM then select Dynamics CRM 2012 plug-in library and press OK.

Step 2:
Enter the credentials and press log on and if you successfully login you will see your organizations in drop down. Select your organization from dropdown and select solution from solution name dropdown box and press ok.
Step 3:
After pressing ok your project will created next step is to right click on your project and click on Properties as mentioned in above fig.
You will see a window with project properties and then click Signing and check Sign the assembly button enter your key file name and uncheck Protect my key file with a password check box.
Step 4:
Next step is to create Entities wrapper.
Right click on Entities in CRM Explorer bar and click on generate wrapper.
It will automatically generate a wrapper class for us we need to add the reference in our class only.
Open your Plugin.cs file and paste following code
Step 5:
 




using System;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using PluginWalkthrough.Entities;
 
public class Plugin : IPlugin
{
    public void Execute(IServiceProvider serviceProvider)
    {
        IPluginExecutionContext context = (IPluginExecutionContext)
        serviceProvider.GetService(typeof(IPluginExecutionContext));
 
        Entity entity;
 
        // Check if the input parameters property bag contains a target
        // of the create operation and that target is of type Entity.
        if (context.InputParameters.Contains("Target") &&
        context.InputParameters["Target"] is Entity)
        {
            // Obtain the target business entity from the input parameters.
            entity = (Entity)context.InputParameters["Target"];
 
            // Verify that the entity represents a contact.
            if (entity.LogicalName != "contact") { return; } // Write your entity name in which you want to trigger your plugin
        }
        else
        {
            return;
        }
 
        try
        {
            IOrganizationServiceFactory serviceFactory =
                (IOrganizationServiceFactory)serviceProvider.GetService(
            typeof(IOrganizationServiceFactory));
            IOrganizationService service =
            serviceFactory.CreateOrganizationService(context.UserId);
 
            var id = (Guid)context.OutputParameters["id"];
           
            //Write your business logic here
        }
        catch (FaultException<OrganizationServiceFault> ex)
        {
            throw new InvalidPluginExecutionException(
            "An error occurred in the plug-in.", ex);
        }
    }
 
 
}
Here you go your plugin is ready to build and for deploy. You can add your business logic in the plugin.

For deploying a plugin please check following link.
http://msdn.microsoft.com/en-us/library/gg309580.aspx


I hope it helps some one :)
 
 
 
 

Monday, February 25, 2013

How to publish all customization in CRM 2011 using .NET C#

I am developing a tool that creates attributes on runtime and I need to publish all the customization’s and for this purpose I am just exploring SDK and found this message request
"PublishAllXmlRequest" which is used to publish all customization in CRM 2011 here is the complete syntax I hope it help’s some one
J

PublishAllXmlRequest publishReq= new PublishAllXmlRequest();

service.Execute(publishReq);

Note: Make sure you have added a namespace Microsoft.Crm.Sdk.Messages;

Thanks

Case Study: Implementing MS Dynamics CRM 2011 for a Newsgroup


Case study (Newspaper group)
The purpose to write the blog is to tell the people that how Dynamics CRM improve the performance of a newspaper group. Recently I have an experience of working with a Multilanguage newspaper group based in UK. They care about their customers and they are much interested in implementing contract base system which uses very complex business roles and it has 10+ offices in different part of the world and has a lot of agents in all over the world.
Business needs
They have already running a system which is a custom desktop application it has a central database which is linked with all offices. But the application is start causing issues and is really difficult to upgrade or integrate with any system. The application does not support direct marketing list functionality and the main feature of marketing. The client is much interested in reliable fast and accurate system which must be less expansive and they must have good control on it.

Solution:
After consulting we decided to go for Dynamics CRM for Marketing and contract management and for financial management we decided to use Dynamics NAV. Dynamics CRM has a great feature of Marketing and contract system as a built in functionality. They need to store all the data in CRM and also wants old data in new system. And using the NAV contactor we can connect both CRM and NAV. Even If they want to implement other dynamics products it’s easy for them because Dynamics gives adaptor functionality for all the dynamics products.

Benefits for using Dynamics CRM
1. Dashboard
CRM Dashboards allow us to drilldown to the data due to this functionality a business can take more efficient and quick to respond to issues and new opportunities.
Executives can take decisions from dashboard visibility for example if any country has less revenue generated with comparison to the last month the executives will try to find the cause and focus on that country before anything goes in loss.

2. Contract management
After implementing dynamics CRM they can easily manage contracts and have better control on Marketing and pricing.
3. Expands the Agents

In newspaper group agents are great resource of profit. Using accounts and partner portal functionality we can increase agents as much as the newspaper industry can. And using contract management system we can distribute there commission easily. 4. Ad Management
We can use Product as Ad it’s easy for group to manage with contracts.
5. Availability of old data in new systemUsing import feature of Dynamics CRM we can easily migrate data to CRM from any old system.
6. ReportingReporting is really easy in CRM anyone who has a little knowledge about CRM can easily develop reports.
7. Easy to useDynamics CRM has office type UI so if any one who is familiar with office can easily and quickly learn CRM.


This is an open blog any one can share his/her idea's in comments and they are highly appreciated.

Thanks :)


Wednesday, January 30, 2013

Understanding and Development of Custom Workflow Activities in Microsoft Dynamics CRM


As we all know with the release of rollup 12 we can develop custom workflow activity for CRM 2011 online too. We can develop custom workflow for CRM online here are the steps to develop custom workflow activity for CRM 2011 online using visual studio 2012 although there is no difference between developing workflow activity in VS 2010 and VS 2012 but due to great feature of VS 2012 i decided to make the workflow activity in VS 2012.

Prerequisites:
1. Latest SDK (Download Latest SDK)
2. CRM 2011 must have rollup 12 (By default all online CRM has been update to rollup 12)




Step 1: Create a new CRM Packedge in Visual Studio give any name

Step 2: After you select your project type you will saw a popup box asking for your credtionals fill the form and click ok





Step 3: Add a new CRM 2011 workflow liberary in CRM Packedge solution

Step 4: Right click on CRM 2011 workflow library and click on properties and go to Signin tab

Step 5: From chosse a signing name key file optionset select new the below window will opens give any name and uncheck the checkbox click ok and save your project







Step 6:
After signing your workflow add a new workflow activity class click on your workflow activity -> right click-> add new item


Step 7:
Select workflow activity class as your new item after giving name click ok

Step 8:After you select workflow activity class CRM asks you for below information fill the information and all the information is required

Step 9: Implement your custom business logic

Step 10:  After completing your implementation right click on RegisterFile.crmregister and change IsolationMode to Sandbox




Step 11: Go to Build -> Deploy from visual studio 2012 main menu.
Step 12: After deployment complete you can see your custom workflow activity in your steps



Note: The error that i found while developing custom workflow activity is
1. "Error registering plugins and/or workflows. Description name must be specified Parameter name: description"  if i skip step 8 i got the above error so make sure your have filled all the fields that is in the form.
2. Error registering plugins and/or workflows. Action failed for assembly 'CrmPackageOnline.WorkflowOnline, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f24fa33afcfbc3ec': Assembly must be registered in isolation.    C:\Program Files (x86)\MSBuild\Microsoft\CRM\Microsoft.CrmDeveloperTools.12.targets    176    4    CrmPackageOnline
if you skip step 10
Resolution change the RegisterFile.crmregister xml and IsolationMode to Sandbox




 

Tuesday, January 22, 2013

Using ExecuteMultipleRequest with CRM 2011

ExecuteMultipleRequest METHOD IN ACTION

As we all know CRM 2011 rollup 12 has lunched a new ExecuteMultipleRequest method.
Today i am just exploring this great feature and develop a code snippets and wants to share with you.
Note: Make sure you have latest SDK of CRM 2011

            var service = new XrmServiceContext("Xrm");
            OrganizationRequestCollection collection = new OrganizationRequestCollection();
            for (int i = 0; i <= 5000; i++)
            {
                CreateRequest createRequest = new CreateRequest // create a request and add the request in collection
                {
                    Target = GetEntityRecord()    // this method could returns any entity i.e account, contact etc you could implement your own logic to get the target entity
                };
                collection.Add(createRequest);
            }

            ExecuteMultipleRequest excuteMultipleRequest = new ExecuteMultipleRequest // Create ExecuteMultipleRequest object with the above collection
            {
                Requests = collection,
                Settings = new ExecuteMultipleSettings
                {
                    ContinueOnError = false,
                    ReturnResponses = true
                }
            };
            ExecuteMultipleResponse executeMultipleResponse = (ExecuteMultipleResponse)service.Execute(excuteMultipleRequest); //Execute the request
            var results = executeMultipleResponse.Results; //Request result


I hope it helps some one.

What's New in Microsoft Dynamics CRM Rollup 12 for Developers

1. Extended Browser Support

As we all know now CRM supports multiple browser support (Yahoo!) now we have to write the code differently as we have to stay near to Xrm.Page object and do supported customization we don’t need any changing to support other browsers.

View of CRM in Google chrome

Fig. 1

Note: If you want to check the browser compatibility mode you can use the custom code validation tool Download custom code validation.

2. New feature in Activity Feeds

CRM introduces new Social media functionality of like/unlike.

 Fig. 2

3. New UI for Sales and Customer Service and Product Update Functionality

New user experiences has been added for Opportunity , Lead and Case.

Fig. 3

4. Custom Workflow Activities for Microsoft Dynamics CRM Online

Now we can register custom workflow activities with CRM online too

Note: If you want to create workflow activity please check this link Create and deploy workflow activity using Developer toolkit

5. Developer Toolkit Support for Microsoft Visual Studio 2012

With rollup 12 Microsoft has also lunched The Developer Toolkit for Microsoft Dynamics CRM 2011 and Microsoft Dynamics CRM Online that supports Microsoft Visual Studio 2012. The installer can be found in the SDK download in the sdk\tools\developertoolkit\ folder.
Download CRM Toolkit

6. Bulk Data Load

If you want to Load bulk data in CRM now you can use ExecuteMultipleRequest message.

For more details please check following link
New features for developers in rollup 12



Wednesday, January 16, 2013

MS Dynamics CRM vs Salesforce - 5 Deciding Factors



In my last project my client asks me to give him some suggestion to choose the CRM product between Microsoft Dynamics CRM and Salesforce. And depending upon the below criteria I told him why to go for Dynamics CRM.

Here is a comparison of two major CRM products

1. In Microsoft Dynamics CRM we have a lot of options to integrate it with any other application and also office 365 makes it really easy to manage all the things on one place. And in Salesforce we have limited integration capabilities.

2. You could use any deployment option for Microsoft CRM (on-premise, Saas, on-premise hosted, or hybrid) depending upon your business requirement for example if you have resources to manage deployment on server you could go for on-premise version otherwise you have an option of online but in Salesforce you have only one option which is SaaS

3. Overall cost of Dynamics CRM is cost effective you could go for on-premise or online but for salesforce its twice than Microsoft Dynamics CRM online edition and if you need to do more customization you have to go for enterprise edition which is very costly and you have to learn a new language called Apex to add any new feature in it.

4. We could configure almost everything in Dynamics CRM like workflows, role-base views, filed level security its SDK is very powerful we could integrate any application with the help of web services. But Salesforce is not highly configurable.

5. CRM 2013 or CRM 2011 (rollup 12) has built in Yammer, Skype and Bing Maps integration. And upcoming rollup also has cross browser capabilities.

Depending upon the above criteria I suggest my client to go for Dynamics CRM because it is cost effective and if he wants to automate the overall process and uses its custom feature. 

I hope it helps someone :)