serving the solutions day and night

Pages

Showing posts with label xrm. Show all posts
Showing posts with label xrm. Show all posts

Tuesday, September 10, 2013

Programming Models for MS Dynamics CRM 2011


Key programmability scenarios for MS Dynamics CRM 2011



Early-bound – MS Dynamics CRM 2011 uses an entity data model and Windows Communication Foundation (WCF) Data Services technologies to provide a new set of tools that interact with Microsoft Dynamics CRM. For example: an organization service context that tracks changes to objects and supports .NET Language-Integrated Query (LINQ) queries to retrieve data from MS Dynamics CRM. Early bound classes generated directly from the metadata, which include all customizations.
CrmSvcUtil.exe - CRM Dynamics 2011 Code Generation Tool


Wednesday, September 4, 2013

MS Dynamics CRM - Bulk Delete using XRM

Import
MSDynamicsCRM2011.DNS.Entities
microsoft.crm.sdk.proxy
microsoft.xrm.client
microsoft.xrm.sdk
System.ServiceModel
System.Data.DataSetExtensions

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using GCEntity = BT.CRM2011.DNS.Entities;
using System.ServiceModel.Description;

namespace CRM.Audit.BulkDelete
{
    class Audit
    {
        private BulkDeleteResponse _bdRes;
        private Guid _bdResID;
        private Guid _bdGUID;
        private ConditionExpression _conExp;

//Delete Method
        public void Delete()
        {
            SystemJob(GCEntity.dns_audit.EntityLogicalName, "Audit Bulk Delete - Code", _conExp);
            Console.WriteLine("Audit Deleted");
            SystemJob(GCEntity.Contact.EntityLogicalName, "Contact Bulk Delete - Code", _conExp);
            Console.WriteLine("Contact Deleted");
            Console.ReadLine();
        }


Thursday, August 29, 2013

MS Dynamics CRM 2011 - Paging Retrieve Multiple Records

QueryExpression query = new QueryExpression(Contact.EntityLogicalName);
EntityCollection coll;
query.PageInfo.PageNumber = 1;
query.ColumnSet = new ColumnSet("firstname", "lastname");
do
{
    int RecordId = 1;
    coll = CRMServiceProxy.RetrieveMultiple(query);
    foreach (Entity e in coll.Entities)
    {
        Console.WriteLine(query.PageInfo.PageNumber + " - " + RecordId + " - " + e.Attributes["firstname"] + " - " + e.Attributes["lastname"]);
        RecordId++;
    }
    query.PageInfo.PageNumber++;
}
while (coll.MoreRecords);


public static OrganizationServiceProxy CRMServiceProxy
        {
            get
            {
                var uri = new Uri(System.Configuration.ConfigurationManager.AppSettings["CrmOrganizationUri"]);

                //Authenticate using credentials of the logged in user;      
                var cnt = new ClientCredentials();
                cnt.Windows.ClientCredential.Domain = System.Configuration.ConfigurationManager.AppSettings["CrmDomain"].ToString();
                cnt.Windows.ClientCredential.UserName = System.Configuration.ConfigurationManager.AppSettings["CrmUserName"].ToString();
                cnt.Windows.ClientCredential.Password = System.Configuration.ConfigurationManager.AppSettings["CrmPassword"].ToString();
                //cnts.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

                var sp = new OrganizationServiceProxy(uri, null, cnt, null);
                sp.EnableProxyTypes();

                return sp;
            }
        }

Monday, May 6, 2013

Microsoft Dynamics CRM – Exporting more than 10,000 rows to Excel


Log into SQL Management Studio, OPEN CRM Database

update OrganizationBase set MaxRecordsForExportToExcel = 30000 where OrganizationId = ‘GUID of your organization’ 

Update through XRM

Organization organization = new Organization();
organization.Id = “your org id”;
organization.MaxRecordsForExportToExcel = 30000;
service.Update(organization);


Dynamics CRM - Change Contact Name Format

UPDATE contactbase SET fullname = ISNULL(lastname, ”) + ‘, ‘ + ISNULL(firstname, ”)

import file is too large to upload

UPDATE ServerSettingsProperties SET IntColumn =15 where  columnname=‘ImportMaxAllowedFileSizeInMB’ 

Increase Grid Page Limit

Open the UserSettingsBase table,  change the PagingLimi.

Monday, April 22, 2013

CRM Linq

//PickList values
private Dictionary<String, String> PickList(String entityName, String attID, string attName)
{
    Dictionary<String, String> dic = new Dictionary<String, String>();
    IOrganizationService service = (IOrganizationService)serviceProxy;
    QueryExpression qryExp = new QueryExpression(entityName);
    qryExp.ColumnSet = new ColumnSet(attName);
    EntityCollection entCollection = service.RetrieveMultiple(qryExp);
    dic = entCollection.Entities
        .Where(e => (e.Attributes.ContainsKey(attName)))
        .ToDictionary(e => e.Attributes[attID].ToString(), e => e.Attributes[attName].ToString());
    /*int i=1;
    foreach (var c in entCollection.Entities)
    {
        if (c.Attributes.ContainsKey(attName))
        {
        dic.Add(c.Attributes[attID].ToString(), c.Attributes[attName].ToString());
        }
    }*/
}

Wednesday, April 17, 2013

XRM Data Transfer Error

Error 1
System.InvalidOperationException: Sequence contains no matching

Solution
PickList or OptionSet value is missing or Number  not matched

Error 2
System.Data.SqlClient.SqlException (0x80131904): Timeout expired.

Solution
Add DNS.dbml -> DNS.designer.cs -> DNSDataContext method
partial void OnCreated()
{
    //Set the timeout value to 300 = 50 Min.
    base.CommandTimeout = 3000;
}

CRM Plugin Code - Add/Update Entity, Connect WebService, Update Database

//Update Same Entity, Other entity, create new record in other entity  and connect to WebService
//Update to database  and
//Webservice update to database

using System;
using System.Diagnostics;
using System.Linq;
using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Query;
using System.Xml;
using System.Net;
using GCEntity = CRMEnt.Entities;
using System.Text;
using System.ServiceModel;

CRM 2011/2013 Development Toolkit

http://msdn.microsoft.com/en-us/library/hh372957%28v=crm.6%29.aspx

With the Developer Toolkit, you can do the following:
  • Easily generate strongly typed proxy classes without having to run CrmSvcUtil.exe.
  • Generate plug-in code so you can immediately begin to write code for business logic.
  • Edit and register plug-ins without using the Plug-in registration tool.
  • Create new web resources or extract existing web resources, add them to your solution, edit them, and deploy changes all within Visual Studio.
  • Create and edit workflow and dialog processes from within Visual Studio.
  • Get easy access to entity and option set definitions, security role and field security profile information in Visual Studio.
Download SDK http://www.microsoft.com/en-us/download/details.aspx?id=40321

Monday, February 25, 2013

MS Dynamics CRM Solutions

CRM Customizations - Customize through a web-based interface without any programming expertise or use the MS Dynamics CRM software development kit (SDK) to programmatically alter the metadata. Two default security roles associated with system customization privileges: System Administrator and System Customizer

Solutions are packages of customizations and metadata that allow system administrators and software developers to create, transport, and maintain business applications or functionality that run on the Microsoft Dynamics CRM framework.

Settings area -> Click Customizations ->  Click Customize the System to open the solution.

Tuesday, February 12, 2013

Get CRM PickList & Global OptionSet using c#

using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;

Uri OrganizationUri = new Uri(System.Configuration.ConfigurationManager.AppSettings["CRM_Organization_URI"].ToString());
Uri HomeRealmUri = null;
Dictionary<String, String> dicState = new Dictionary<String, String>();
Dictionary<String, String> dicSuffix = new Dictionary<String, String>();

Tuesday, November 27, 2012

CRM Dynamics 2011 - Dynamic Entity using Service Data Context

Refer the blog, how to create CRM Entites and Service Data Context http://makdns.blogspot.com/2012/11/crmsvcutilexe-crm-dynamics-2011-code.html

Add the CRM.Entities.cs file to your project.

Insert, Update, Delete, View and Select Entities list using c#.

Monday, November 26, 2012

CRM Dynamics 2011 - Dynamic Entity

Using C# and IOrganizationService Web Service - A Simple Application will display, add, modify and delete Entity records.

Form design

<div>
        <strong>Contact Form - <asp:Button ID="Insert" runat="server" OnClick="Insert_Click" Text="Insert" /><br /></strong>
        <asp:Literal ID="litViewAll" runat="server"></asp:Literal><br />
        <asp:Panel runat="server" ID="panDetails" Visible="false">
        First Name<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox><br />
        Last Name<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox><br />
        Address<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox><br />
        City<asp:TextBox ID="txtCity" runat="server"></asp:TextBox><br />
        Zip<asp:TextBox ID="txtZip" runat="server"></asp:TextBox><br />
        State<asp:DropDownList ID="ddlSList" runat="server" AppendDataBoundItems="true">
            <asp:ListItem Selected="True" Text="Select SList" Value="00000000-0000-0000-0000-000000000000"/>
        </asp:DropDownList><br />
        Municipality Name<asp:DropDownList ID="ddlJList" runat="server" AppendDataBoundItems="true">
            <asp:ListItem Selected="True" Text="Select MList" Value="00000000-0000-0000-0000-000000000000"/>
        </asp:DropDownList><br/>      
        <asp:Button ID="CreateNew" runat="server" OnClick="CreateNew_Click" Text="Create" />
        <asp:Button ID="Delete" runat="server" OnClick="Delete_Click" Text="Delete" />
        <asp:Button ID="Update" runat="server" OnClick="Update_Click" Text="Update" /><br />
        </asp:Panel>
        </div>

Friday, November 23, 2012

CrmSvcUtil.exe - CRM Dynamics 2011/2013/2015 Code Generation Tool - Early Bound

CrmSvcUtil.exe command-line tool, called the Microsoft.Xrm.Client.CodeGeneration extension, which you can use to generate the data context and data transfer object classes for your Microsoft Dynamics CRM organization.

CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization,Microsoft.Xrm.Client.CodeGeneration" /url:http://<Server_Name>/<Organization_Name>/XRMServices/2011/Organization.svc /username:uid /password:pwd /out:"CRMEntities.cs" /namespace:CRM.Entities /serviceContextName:CrmServiceContext

Generate Custom Action as Early Bound (parameter /generateActions)
CrmSvcUtil.exe /url:http://<Server_Name>/<Organization_Name>/XRMServices/2011/Organization.svc /username:uid /password:pwd /out:"c:\crmprojects\CRMEntities.cs" /namespace:DNS.CRM.Entities /serviceContextName:CrmServiceContext /generateActions

Reference - http://msdn.microsoft.com/en-us/library/ff681563.aspx 

Wednesday, November 21, 2012

IncludeExceptionDetailInFaults - Display Hidden Error

Create a simple web application to add contact data into the CRM system using c# and IOrganizationService Web Service.

1)Create Empty web application

2)Add References
microsoft.xrm.sdk.dll
microsoft.crm.sdk.proxy.dll
System.Runtime.Serialization
System.ServieModel