Friday, 31 May 2013

Publishing CRM entities in SharePoint

Thought Process:
1) CRM 2011 provides SDK and I can always develop custom solutions. If I choose to refer to “Walkthrough: Build a Web Application That Connects to Microsoft Dynamics CRM 2011 Using Developer Extensions” I can easily display CRM 2011 entity information in a Web Application.
2) That means I can easily transform those custom solutions (like a Web Application) into a SharePoint 2010 web part, and bingo! We are all set!
Catch:
1) CRM 2011 is based on .Net framework 4.0 and SP 2010 is on .Net 3.5. So if you try to implement the step 2 you can’t even build your SharePoint Web Part forget about deploying it.
Resolution [Important Steps]:
image_thumb25
1) Publish an intermediary WCF service with relevant methods to expose information from CRM 2011.
2) Create a SharePoint Web Part and make appropriate calls to the WCF service and then transform the result set as per your needs for the end user.

The Steps in detail:

1) We need to create and publish a WCF service to call in CRM 2011. This service can have multiple facets based on your needs; may be you intend to perform add/edit/delete apart from just “display” so create the WCF methods judiciously. For now I will stick to the display part.
IMP: The code blocks below doesn’t confirm to the coding best practices but does work, and I am sure you guys can transform it accordingly. I have ripped the pieces from from all over the web
a) Generate Early Bound Types:
Run the CrmSvcUtil.exe tool, with the Microsoft.Xrm.Client.CodeGeneration extension, to generate your entity classes and service contexts.
The following example command creates a file called “Xrm.cs” that points at an instance of Microsoft Dynamics CRM. Note that the Microsoft.Xrm.Client.CodeGeneration.dll file must be in the same directory as the CrmSvcUtil.exe file, or in the system GAC, when you run this command.
crmsvcutil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration"
/out:Xrm\Xrm.cs /url:
http://dpm2012/fabrikam/XRMServices/2011/Organization.svc /domain:CONTOSO /username:spfarm
/password:Welcome@123 /namespace:Xrm /serviceContextName:XrmServiceContext

b) Use Visual Studio 2010 to create a WCF Service Application (ensure .NET Framework 4).
Img1_thumb3
c) Right-click the project in Visual Studio, click Add, and then click Existing Item. Select the “xrm.cs” file that you created when you generated the early bound types.
d) Right-click the project in Visual Studio, click Add, add a new class to the project. The Add New Item dialog box appears. Rename the class as Entities.cs. Similarly add one more class and name it as Views.cs
e) Add couple of properties in both these classes (please name it appropriately)
public string MyProperty { get; set; }
public string MyProperty1 { get; set; }
 
f) Add the references as shown below (for the CRM dll the Source will be SDK\bin, don’t search for C:\Shariq Smile)
 
image_thumb7
g) Now your Solution should look more like below (few more references might have been inadvertently added)
 
image_thumb3
 
h) Right-click the project in Visual Studio and add the Service Reference for the Organization.svc
 
 
i) Open the interface IService1.cs and replace the ServiceContract with the code below:
 
[ServiceContract]
    public interface IService1
    {
 
        [OperationContract]
        string GetMessage();
 
        [OperationContract]
        List<Entities> GetEntityData();
 
 
        [OperationContract]
        List<Views> GetViewData(int SelectedEntity);
 
        [OperationContract]
        DataSet GetCompleteData(string _SavedQueryId);
 
    }
j) Now we need to implement the Service1.svc, copy the below code (make appropriate changes for your OrganizationUri i.e. Organization.svc )
    public class Service1 : IService1
    {
        public List<Entities> GetEntityData()
        {
        ClientCredentials Credentials = new ClientCredentials();

        Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

        //This URL needs to be updated to match the servername and Organization for the environment. 

        Uri OrganizationUri = new Uri("http://DPM2012/TailspinToysDB/XRMServices/2011/Organization.svc");
        List<Entities> EntityList = new List<Entities>();
        Uri HomeRealmUri = null;
        using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, 
        Credentials, null))
        {

            Microsoft.Xrm.Sdk.IOrganizationService service = serviceProxy as Microsoft.Xrm.Sdk.IOrganizationService;

            RetrieveAllEntitiesRequest request = new RetrieveAllEntitiesRequest()
            {
                EntityFilters = EntityFilters.Attributes,
                RetrieveAsIfPublished = true
            };

            // Retrieve the MetaData.
            RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)serviceProxy.Execute(request);

            foreach (EntityMetadata currentEntity in response.EntityMetadata)
            {
                if (currentEntity.IsCustomizable.Value == true)
                {
                    foreach (AttributeMetadata currentAttribute in currentEntity.Attributes)
                    {

                        Entities e = new Entities();
                        e.MyProperty = currentEntity.LogicalName;
                        e.MyProperty1 = currentEntity.ObjectTypeCode.Value.ToString();

                        if (EntityList.Where(en => en.MyProperty.Equals(e.MyProperty) && 
                        en.MyProperty1.Equals(e.MyProperty1)).Count() == 0)
                        {
                            EntityList.Add(e);
                        }
                    }
                }
            }

        }
        return EntityList;
        }

        public List<Views> GetViewData(int paramSelectedEntity)
        {
        ClientCredentials Credentials = new ClientCredentials();

        Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

        //This URL needs to be updated to match the servername and Organization for the environment. 

        Uri OrganizationUri = new Uri("http://dpm2012/TailspinToysDB/XRMServices/2011/Organization.svc");

        Uri HomeRealmUri = null;
        List<Views> ViewsList = new List<Views>();

        using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, 
        Credentials, null))
        {
            serviceProxy.EnableProxyTypes();

            Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;

            // Retrieve Views
            QueryExpression mySavedQuery = new QueryExpression
            {
                ColumnSet = new ColumnSet("savedqueryid", "name", "querytype", "isdefault", "returnedtypecode", 
                "isquickfindquery"),
                EntityName = SavedQuery.EntityLogicalName,
                Criteria = new FilterExpression
                {
                    Conditions =
        {
                
            new ConditionExpression
            {
                AttributeName = "returnedtypecode",
                Operator = ConditionOperator.Equal,
                Values = {paramSelectedEntity}
            }
        }
                }
            };
            RetrieveMultipleRequest retrieveSavedQueriesRequest = new RetrieveMultipleRequest { Query = mySavedQuery };

            RetrieveMultipleResponse retrieveSavedQueriesResponse = 
            (RetrieveMultipleResponse)serviceProxy.Execute(retrieveSavedQueriesRequest);

            DataCollection<Entity> savedQueries = retrieveSavedQueriesResponse.EntityCollection.Entities;
                
            foreach (Entity ent in savedQueries)
            {
                SavedQuery rsq = (SavedQuery)ent;
                if (rsq.IsDefault == true)
                {
                    Views e = new Views();
                    e.MyProperty = rsq.Name.ToString();
                    e.MyProperty1 = rsq.Id.ToString();
                    ViewsList.Add(e);
                }
            }
        }

        return ViewsList;           

        }

        public DataTable convertEntityCollectionToDataTable(EntityCollection BEC)
        {
            DataTable dt = new DataTable();
            int total = BEC.Entities.Count;
            for (int i = 0; i < total; i++)
            {
                DataRow row = dt.NewRow();
                Entity myEntity = (Entity)BEC.Entities[i];
                var keys = myEntity.Attributes.Keys;
                foreach (var item in keys)
                {
                    string columnName = item;
                    string value = getValuefromAttribute(myEntity.Attributes[item]);
                    if (dt.Columns.IndexOf(columnName) == -1)
                    {
                        dt.Columns.Add(item, Type.GetType("System.String"));
                    }
                    row[columnName] = value;
                }
                dt.Rows.Add(row);
            }
            return dt;
        }

        private string getValuefromAttribute(object p)
        {
            if (p.ToString() == "Microsoft.Xrm.Sdk.EntityReference")
            {
                return ((EntityReference)p).Name;
            }
            if (p.ToString() == "Microsoft.Xrm.Sdk.OptionSetValue")
            {
                return ((OptionSetValue)p).Value.ToString();
            }
            if (p.ToString() == "Microsoft.Xrm.Sdk.Money")
            {
                return ((Money)p).Value.ToString();
            }
            if (p.ToString() == "Microsoft.Xrm.Sdk.AliasedValue")
            {
                return ((Microsoft.Xrm.Sdk.AliasedValue)p).Value.ToString();
            }
            else
            {
                return p.ToString();
            }
        }

        public DataSet GetCompleteData(string _strSavedQueryId)
        {
        DataSet ds = new DataSet();

        Guid _SavedQueryId = new Guid(_strSavedQueryId);

        ClientCredentials Credentials = new ClientCredentials();

        Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

        //This URL needs to be updated to match the servername and Organization for the environment. 

        Uri OrganizationUri = new Uri("http://dpm2012/TailspinToysDB/XRMServices/2011/Organization.svc");

        Uri HomeRealmUri = null;


        using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, 
        Credentials, null))
        {
            serviceProxy.EnableProxyTypes();

            Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;

            ColumnSet cSet = new ColumnSet("savedqueryid", "fetchxml");

            SavedQuery rsq = (SavedQuery)service.Retrieve(SavedQuery.EntityLogicalName, _SavedQueryId, cSet);

            RetrieveMultipleRequest req = new RetrieveMultipleRequest();
            FetchExpression fetch = new FetchExpression(rsq.FetchXml);
            req.Query = fetch;
            RetrieveMultipleResponse resp = (RetrieveMultipleResponse)service.Execute(req);
            DataTable ObjDT = convertEntityCollectionToDataTable(resp.EntityCollection);
            ds.Tables.Add(ObjDT);

        }
        return ds;
        }
    }
k) Now the CRM WCF Service is ready and we can publish it at IIS. The steps to publish any WCF service can be found easily over web. Starters can refer to http://debugmode.net/2010/09/07/walkthrough-on-creating-wcf-4-0-service-and-hosting-in-iis-7-5/. Skip the Service creation steps from this blog just refer to Publishing steps and also ensure to test it locally using a local Client.
If you have reached here successfully, the battle is almost won Smile
2) Now we just need to create a simple SharePoint 2010 Visual Web Part to consume this service as per need.
a) Use Visual Studio 2010 to create a new Visual Web Part project.
b) Right Click the project and Add the Service Reference for our CRM Service published in Step 1.
image_thumb13
c) Add the following code to VisualWebPart1UserControl.ascx :
<asp:DropDownList ID="ddlEntityList" runat="server" AutoPostBack="True" 
OnSelectedIndexChanged="ddlEntityList_SelectedIndexChanged"></asp:DropDownList>
<asp:DropDownList ID="ddlViewsList" runat="server" AutoPostBack="True" 
OnSelectedIndexChanged="ddlViewsList_SelectedIndexChanged"></asp:DropDownList>
<asp:GridView ID="gdEntity" ViewStateMode="Disabled" runat="server" />
d) Add the following code to VisualWebPart1UserControl.ascx.cs:
       protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Service1Client proxy = new Service1Client();

                ddlEntityList.DataSource = proxy.GetEntityData();
                ddlEntityList.DataTextField = "MyProperty";
                ddlEntityList.DataValueField = "MyProperty1";
                ddlEntityList.DataBind();
            }
        }

        protected void ddlEntityList_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlViewsList.Items.Clear();
            int index = Convert.ToInt32(ddlEntityList.SelectedValue);
            Service1Client proxy = new Service1Client();

            ddlViewsList.DataSource = proxy.GetViewData(index);
            ddlViewsList.DataTextField = "MyProperty";
            ddlViewsList.DataValueField = "MyProperty1";
            ddlViewsList.DataBind();


        }

        protected void ddlViewsList_SelectedIndexChanged(object sender, EventArgs e)
        {            
            string str = ddlViewsList.SelectedValue;
            Service1Client proxy = new Service1Client();
            gdEntity.DataSource = proxy.GetCompleteData(str);
            gdEntity.DataBind();
        }
e) Right click the Project and deploy to the SharePoint Site.
f) Go to the SharePoint 2010 Site and add the Visual Web Part to a page where you want to display the Web Part. And ‘Bingo’. You should see the something like this:
image_thumb29
This SharePoint Web Part code above is pretty basic in nature for now, but I am sure you can improve upon this sample code – you know, things like:
  • When not to show the ‘View’ Drop Down when the Entity is refreshed.
  • Or when there is no result set we must show appropriate result rather than the Yellow screen of death.
  • Or you want to filter the Grid by removing certain columns from the dataset or renaming the column Header etc.
I leave all it all up to you, as the sample is attached. Use it/Break it and Enjoy !!!

Food for thought

1) In principle this should work for MOSS 2007, for those who are still on it Smile
2) In SharePoint 2013, we can merge the WCF code implementation within the SharePoint web part itself.
You can download the complete sample from here.

Code References

Hope this helps a needy soul!

Share point -MSCRM integration

Part 1 CRM 2011
Within CRM go to Settings \ Document Management
Click on Document Management under Settings Tab from the left Navigation Page
Click on List Components and then Download the list component file from Microsoft Download Center CRM2011-SharePointList-ENU-amd64.exe and extract them
Three files are extracted, AllowHtcExtn.ps1, crmlistcomponent.wsp and mscrmsharepointeula.txt.
Only the crmlistcomponent.wsp will be used in the integration.
Part 2 SharePoint
Open your team site
or SharePoint 2013
Click on Site Action from the Top Link Bar and from the drop down select Site Settings NOTE: these steps may vary slightly for SharePoint online, the final link is the destination but the navigation can be different.
or SharePoint 2013
Click on Solutions under Galleries
or SharePoint 2013
Click on Solution from the top link bar and then click Upload Solution
Browse to the saved file crmlistcomponent.wsp and upload
Activate the wsp file just uploaded. Note: At times this can fail, keep trying and it should activate.
Part 3 back to CRM 2011
Under the Document Management Click on Document Management Settings. Select the entities you want to integrate with SharePoint You will need to specify the URL for your SharePoint Team Site. The url can be a sub site that you have created into you main team site.
Now click next and then Select the base entity
Click on next and it will give you a popup for creating libraries into Sharepoint Online. Just Click OK
CRM will create the folders and give the status as Succeed
Click on finish
Validate everything is working, open an account and click on Documents from the left Navigation Pane, it will give you a popup regarding creating folders in SharePoint, click OK. You can now attach any document or create any document from CRM 2011 online.

Thursday, 30 May 2013

Microsoft CRM 2011 How to Configure IFD Hosted Setup

MSCRM 2011 Build numbers

To determine your current build number from the IE web client, simply:
  1. Browse to your CRM 2011 website
  2. Click on the File tab
  3. Navigate to Help
  4. Click on “About Microsoft Dynamics CRM”

To determine your current build number from the Outlook CRM client:
  1. Open Outlook with the CRM Client installed
  2. Click on the File tab
  3. Click on the CRM side tab
  4. Click on the “About Microsoft Dynamics CRM”  button
See below for a chart of the Dynamics CRM 2011 build versions.  I’ll try to keep it current, so be sure to bookmark and check back later!


Version Release Date Build Number KB Article
Release Candidate 5.0.9688.53 2461082
Beta (On Premise) 5.0.9585.106
Beta (Online) 5.0.9585.107
RTM February 16, 2011 5.0.9688.583 Download RTM
Update Rollup 1 April 7, 2011 5.0.9688.1045 2466084
Update Rollup 2 June 2, 2011 5.0.9688.1155 2466086
Update Rollup 3 July 28, 2011 5.0.9688.1244 2547347
Update Rollup 4 September 22, 2011 5.0.9688.1450 2556167
Update Rollup 5 October 25, 2011 5.0.9688.1533 2567454
Update Rollup 6 January 20, 2012 5.0.9690.1992 2600640
Update Rollup 7 March 22, 2012 5.0.9690.2165 2600643
Update Rollup 8 May 3, 2012 5.0.9690.2243 2600644
Update Rollup 9 Not released because of delay in the Q2 Service Update
Update Rollup 10 August 16, 2012 5.0. 9690.2730 2710577
Update Rollup 11 October 11, 2012 5.0.9690.2835 2739504
Update Rollup 12 Jan 7, 2013 5.0. 9690.3236 2795627
Update Rollup 13 March 26, 2013 5.00.9690.3448 2791312


 ref Url:
http://crmdynamo.com/2011/09/crm-2011-update-rollup-release-build-numbers-and-how-to-find-them/

Third Party Solutions to combine Microsoft CRM and Social Media


Some of the  Third party tools we explored.
1.       Social Integration for Microsoft CRM 2011 with Parrot

Ref Link: http://garethtuckercrm.com/2012/04/27/social-integration-for-microsoft-crm-2011-with-parrot/

Features:
Feature #1 is this consolidated view of your social networks inside your CRM system.  

Feature #2 is the ability to post to all of your social networks at the same time, from Microsoft CRM.   The post composer sits above the Timeline.  You can easily toggle which of your social networks you want your message to post to and you can see the number of characters remaining (constrained to the lowest limit of the networks selected):

Feature #3 is the ability to search LinkedIn, Facebook and Twitter’s feeds for keywords.  Search results appear in Tabs and you can have several on the go and can pin them for on-going reference:
Feature #4 with a click of a button you can create a new Lead, Case, Contact or Account in CRM based on a social media post.  


Licensing Cost:
Account Level             # of Users          Annual Price
Parakeet (Basic):         1-2 Users        Free
Cockatoo (Standard):   3-10Users    $599
King (Professional):    11-50 Users    $2599
Macaw (Enterprise):    51+ Users     $4599






2.       Vibe Social Networking for Microsoft Dynamics CRM by Sonama

Features:

Sonoma Partners created Vibe — an application driven by Microsoft Dynamics CRM data that enables users to see instant updates of the information they want to see, then comment and collaborate on it. Sales teams stay in the loop on key efforts from the marketing and customer service teams without having to click through multiple locations in Microsoft Dynamics CRM.

start with a collection of data feeds, specific to a user, team or other group. Users select the feeds they want to see, so they get the information most relevant to them. Posts to each feed are made automatically based on Microsoft Dynamics CRM data or manually as contributions from other users. The end result: An environment for communities and collaboration in your organization that helps drive user adoption of your Microsoft Dynamics CRM system
 New feed:
Users select the feeds to which they want to subscribe so they see the information most relevant to them. They also can opt to receive real-time notification of updates in Vibe, a daily or weekly e-mail report of their feeds, or access their updates from Vibe’s mobile client.

Updates are comments related to a feed, specific to a Microsoft Dynamics CRM user, business group or team. All feeds and entries are stored in Microsoft Dynamics CRM.

In addition to status updates and comments posted by users, you can configure automated updates with Microsoft Dynamics CRM’s workflow engine for milestones such as launching a marketing campaign, winning an opportunity, or resolving a case.
Licensing Cost:
Mentioned as Free









33.       Social Media Connector for CRM 2011 by iotap

Features:
OTAP’s Social Media Connector for Microsoft Dynamics CRM provides integration with popular social media community like LinkedIn and Facebook. Allowing your internal sales and marketing teams to collaborate against these communities ‘databases help your organization to develop an online presence and also be in touch with your customers/prospects.


 Search for Companies within Linked In or Facebook 
• Search for People within Linked In or Facebook 
• Add Companies
 • Add People 
• Link companies 
• Link People 
• Send Invites for events or webinars 
• Send newsletters

Licensing Cost:
                   Price:  

$349.00 

Test Links : no Trail version















4.       MS CRM 2011 Twitter Integration by CodePlex



Features:
MS CRM 2011 Twitter Integration : Display recent 10 twits related to customer in MS CRM 2011.

Pragmasys has built a HTML web resource which can be added to the account form in MS CRM. 
 
Only for Account  only


Licensing Cost:  Code plex solution for free




Test Links : Not tested












 

5.       LinkedIn for Microsoft Dynamics CRM by LinkedIn

 


Features:

  •       View a lead or contact and automatically see his or her LinkedIn profile and company profile on the same page.
  •   You can also search for your lead or contact, and once you've connected the lead or contact to a LinkedIn profile, the profile will be visible for all users in your environment.
  •        You can search for your lead or contact's company, and once you've connected the company to a LinkedIn company profile, the profile will be visible for all users in your environment.
  •       View an account or opportunity and automatically see the LinkedIn company profile on the same page.
  •        View an activity stream for each of your accounts and opportunities.
  •       Narrow down the activity stream to only show activity from contacts in your accounts.

Licensing Cost:

you will need to sign your team up for LinkedIn Sales Navigator or higher plan.

Features

Sales Basic

From INR 800 a month
Recommended for You

Sales Plus

From INR 1,900 a month

Sales Executive

From INR 3,500 a month


Yes
Yes

 

Sales Basic

From INR 800 a month
Recommended for You

Sales Plus

From INR 1,900 a month

Sales Executive

From INR 3,500 a month


Yes
Yes