Friday, November 23, 2012

Getting Rid of the CRM Export to Excel Message

When you export to Excel from CRM and open the exported spreadsheet in Excel, you will receive the warning:

This warning is due to a security feature in Excel 2007 and greater that checks the contents of a file to make sure that they match the file extension.
Given that the CRM data is exported using XML and saved with an .xls format, Excel doesn’t think that the format of the file is correct.


While this is probably designed to prevent some legitimate security concerns,
it winds up having the opposite effect for people who export frequently from
Excel—since this message will be popping up for them so frequently that they
will be conditioned to always click “Yes.” As a result, more legitimate security
warnings are easily ignored.


There are two options for getting rid of this warning:
1. Group Policy – “Getting IT Right” blog has a good post
on how to globally suppress this warning using group policy.
http://blog.meteorit.co.uk/2010/07/01/annoying-file-format-warning-whenexporting-crm-records-to-excel/
2. Per Computer – You can easily get rid of this warning using a simple
registry change on your computer. The following instructions are for Excel
2010. If you have 2007, the only change is that the location of the registry
folder will be …\Microsoft\OFFICE\12.0\EXCEL\SECURITY.
 1. Open your Registry (Start -> Run -> regedit.exe)
 2. Navigate to HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\14.0\EXCEL\SECURITY
 3. Right click in the right window and choose New -> DWORD
 4. Type “ExtensionHardening” as the name (without the quotes)
 5. Verify that the data has the value “0I


Normal warnings apply—don’t modify your registry unless you know what
you are doing!

Document your CRM installation

Everybody knows the importance of documentation of a project.

There is a free tool which you can download from Codeplex: CRM 4 documentation.

If you want to use this tool on a standalone machine or a machine without internet connection, then you should download and install the following files first:

vstor30.exe
vstor30sp1-KB949258-x86.exe

I do know that this is not a new tool, but not everybody heard about this before. Happy documentation!

Update owner in Plugin MS CRM 2011

This code should run in a POST plug-in:

SecurityPrincipal assignee = new SecurityPrincipal();
assignee.Type = SecurityPrincipalType.User;

// PrincipalId is some known Guid belonging to the user or team that will own this record.
assignee.PrincipalId = new Guid("guid");

// Create the target object for the request.
TargetOwnedAccount target = new TargetOwnedAccount();

//use the below code for custom entity
//TargetOwnedDynamic dyn = new TargetOwnedDynamic();
//dyn.EntityName = "new_book";
//dyn.EntityId = id;

// Set the properties of the target object.
// EntityId is some known Guid belonging to the account that is being assigned to the user.
target.EntityId = id;

// Create the request object.
AssignRequest assign = new AssignRequest();

// Set the properties of the request object.
assign.Assignee = assignee;
assign.Target = target;

// Execute the request.
ICrmService service = context.CreateCrmService(true);
try
{
AssignResponse assignResponse = (AssignResponse)service.Execute(assign);
}
catch (Exception ex)
{
//TODO: Exceptionhandling
}

Thursday, November 22, 2012

Get rid of "Do you want to close this window?" in CRM

You might get this question when opening CRM in Internet Explorer:

The webpage you are viewing is trying to close the window.
Do you want to close this window?
yes no

This message appears in CRM 4.0 only when you are using Internet Explorer 7.0 and you have enabled the application mode setting.Nevertheless, it is an annoying message which you can get rid of!

To do so, open the default.aspx file which resides in the root of the CRM Web site. In this file there are these three lines of code:

var oMe = window.self;
oMe.opener = window.self;
oMe.close();
Modify the second line of this snippet and end up with these three lines:
var oMe = window.self;
oMe.open('','_self','');
oMe.close();

You will no longer receive that message.  Keep in mind that following any update or migration, you might need to reapply the change.

Multiple Column Sort in CRM

Have you ever wondered how to sort multiple columns on an Entity Grid
view?  It's quite simple.
1. Click on the first column header
2. Hold down "shift" key
3. Click on the second column header
Now you will have a second column as the sub-group of the first.

Thursday, November 8, 2012

Retreive parent record values from child entity lookup


function retrieverecord() {
  if (Xrm.Page.getAttribute("childlookupid").getValue() != null) {
    //acount guid no
    var parentcustomerID = Xrm.Page.data.entity.attributes.get("childlookupid").getValue()[0].id;
    var xml = "<?xml version='1.0' encoding='utf-8'?>" +
    "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
    GenerateAuthenticationHeader() +
    "<soap:Body>" +
    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
    "<entityName>parentEntity</entityName>" +
    "<id>" + parentcustomerID + "</id>" +
    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +
        "<q1:Attributes>" +
            "<q1:Attribute>parentattributevalue[attributenames]</q1:Attribute>" +            
        "</q1:Attributes>" +
    "</columnSet>" +
    "</Retrieve>" +
    "</soap:Body>" +
    "</soap:Envelope>";
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    var resultXml = xmlHttpRequest.responseXML;

    var errorCount = resultXml.selectNodes('//error').length;

    if (errorCount != 0) {
        var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
        alert(msg);
    }
    //Display the retrieved value.
    else {
        alert(resultXml.selectSingleNode("//q1:parentattributevalue").nodeTypedValue);
        var cost = resultXml.selectSingleNode('//q1:parentattributevalue').nodeTypedValue;
         
       Xrm.Page.getAttribute("childattribute").setValue(parseInt(cost));
//for retreiving the option set text
//resultXml.selectSingleNode('//q1:parentattributevalue').attributes[0].text;
    }
}
}

Thursday, November 1, 2012

Connecting to CRM Online from an outside caller


Open Visual Studio
Add the following references from the SDK\bin folder.
Microsoft.Xrm.Client.dll
Microsoft.Xrm.Sdk.dll

Add the following references from .NET.
System.Data.Services.dll
System.Data.Services.Client.dll
System.Runtime.Serialization.dll

DEVICE REGISTRATION
You can skip this next step and jump to CREATE EARLY BOUND TYPES if you follow the enhancement in the Eliminating manual device registration post.

There’s a section titled “To Generate your individual device ID and password” in the Create Early Bound Entity Classes with the Code Generation Tool (CrmSvcUtil.exe), but it’s easy to miss.  Follow the instructions from that section:

Open and build the DeviceRegistration project: SDK\Tools\DeviceRegistration\DeviceRegistration.csproj.
Run the executable file from the command line. To register your device, set the /operation parameter to Register.
C:\deviceregistration.exe /operation:Register
Copy the displayed device ID and password values and use them as the deviceid and devicepassword parameter values when you run the CrmSvcUtil tool.

Generate the Class by using below command
crmsvcutil.exe /url:https://demo1.api.crm5.dynamics.com/XRMServices/2011/Organization.svc /o:demo1.cs /n:demo1namespace /u:"emailid" /p:"password" /di: DeviceID /dp: DevicePassword /serviceContextName:demo1context

Add the webform
Add the GridView
goto--> Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using demo1namespace;
using System.Linq;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Client;
using Microsoft.Crm.Sdk;
using System.ServiceModel;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Metadata;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ClientCredentials cc = new ClientCredentials();
        cc.UserName.UserName = "";
        cc.UserName.Password = "";
        ClientCredentials dc = new ClientCredentials();
        dc.UserName.UserName = "DeviceID";
        dc.UserName.Password = "DevicePassword";
        Uri url = new Uri("https://demo.crm5.dynamics.com/XRMServices/2011/Organization.svc");
        using (OrganizationServiceProxy proxy = new OrganizationServiceProxy(url, null, cc, dc))
        {
            proxy.EnableProxyTypes();
            IOrganizationService orgserivce = (IOrganizationService)proxy;
           demo1context context = new demo1context(proxy);
            var query = from con in context.ContactSet
                        where con.LastName.Contains("sample")
                        select new
                        {
                            con.MiddleName,
                            con.LastName,
                            con.FirstName,
                            con.CreatedOn,
                            con.CreatedBy,
                        };
            GridView1.DataSource = query;
            GridView1.DataBind();
        }
    }
}