Wednesday, August 15, 2012

The type or namespace 'Xrm' does not exist error

Every time I am starting a new demo project, and trying to prove something quickly, this error gets me:

The type or namespace 'Xrm' does not exist in the namespace 'Microsoft'

What? How is that possible, I know I have added a reference to Microsoft.Xrm.sdk.dll assembly, I tripled checked that.

The problem is, by default new Visual Studio client projects (Console Application, Windows Form and so on) are set to use the .NET Framework 4 Client Profile, which is a subset of the .NET Framework that was optimized for client applications.

Unfortunately, to work with CRM you need the full version of the .NET Framework. So, to fix this issue, just set the Project Target Framework to .NET Framework 4 and you should be good to go.

Starting with the .NET Framework 4.5, the Client Profile has been discontinued and only the full redistributable package is available. Optimizations provided by the .NET Framework 4.5, such as smaller download size and faster deployment, have eliminated the need for a separate deployment package. The single redistributable streamlines the installation process and simplifies your app's deployment options.

When you install the .NET Framework 4.5, the .NET Framework 4 Client Profile is updated to the full version of the .NET Framework.

Source: MSDN

Thursday, April 19, 2012

Error running custom CRM reports

If you are getting the following errors running a custom CRM report:

Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near ' <html> Do you want to continue running scripts on this page?

Or

System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception.
System.ComponentModel.Win32Exception: The target principal name is incorrect

Usually this happens if the SPNs of the CRM web service are not set properly and SRS server is unable to get a Service Ticket from the Ticket Granting Server.

To solve it, register the following SPNs:

  • setspn -a http/<CrmApplicationServerName> <CrmAppPoolServiceUserAccount> (E.g. setspn -a http/devcrmserver domain\crmappservice)
  • setspn -a http/<CrmApplicationServer FQDN> <CrmAppPoolServiceUserAccount> (E.g. setspn -a http/ devcrmserver.domainname.com domain\crmappservice)

NOTE: If you have multiple CRM Application servers, you would need to do this for each server.

NOTE: If after you make this change, your users start complaining they can no longer log into CRM, make the following changes on your CRM server ApplicationHost.config file:

1. Open the ApplicationHost.config file in a text editor.
By default, this file is located at %windir%\system32\inetsrv\config\ (Crm server).
For all folders under the Default Web Site location path, set the value of the WindowsAuthentication element and the useAppPoolCredentials attribute to true.

For example:
<system.webServer>
<security>
<authentication>
<windowsAuthentication enabled="true" useAppPoolCredentials="true" />
</authentication>
</security>
</system.webServer>

Try run any of customized reports again, they should work like other any out-of-the-box reports.

2. Run an iisreset

You can find more information here:
1. http://social.microsoft.com/Forums/en/crm/thread/f1c7384f-0eb0-4bf2-a175-bc7fa30e204b
2. http://blog.sonomapartners.com/2007/04/kerberos_and_de.html

Wednesday, April 11, 2012

CRM Report Error: Guid should contain 32 digits with 4 dashes

You receive the following errors when you run a Microsoft Dynamics CRM report in the SRS Report Manager or SRS Report Server:

An error has occurred during report processing (rsProcessingAborted)  Cannot create a connection to data source ‘CRM.’ (rsErrorOpeningConnection)  Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

This error occurs in Microsoft Dynamics CRM 2011 because the Microsoft Dynamics CRM Reporting Extensions requires the user's SystemUserId value as the Log in name and the user's OrganizationId value as the password.

When a report runs inside Microsoft Dynamics CRM, these values are passed automatically. These values must be entered manually when the report is run directly from SQL Server Reporting Services.

Obtain the SystemUserId and OrganizationId from the database and manually enter the values using the following steps:

  • Connect to the SQL server machine that contains the Microsoft Dynamics CRM databases as a user that has admin rights to SQL Server.
  • Click Start, click All Programs, click Microsoft SQL Server, and then click SQL Server Management Studio.
  • Click New Query.
  • Click File, click New, and then click Database Engine Query.
  • Select your <organization>_MSCRM from the dropdown list.
  • Execute the following query:
    • Select FullName, SystemUserId, OrganizationId 
    • From FilteredSystemUser
    • Order by FullName
  •  Locate the user that will run the report.
  • Enter the SystemUserId value into the Login Name box on the report.
  • Enter the OrganizationId value into the password field on the report.
  • Run the report.
Reference:http://support.microsoft.com/kb/2006869

Friday, March 9, 2012

CRM 2011 Report "Pre-Filter" Configuration

  1. Go to Workplace -> Reports 
  2. Select the report in the Reports grid. 
  3. In the Ribbon, click Edit Default Filter configuration button (figure 1). 
  4. In the Report Viewer dialog box, define the default filter criteria that will be used every time the report runs. 
  5. Click Save Default Filter. 
  6. Run the report. 


That's it. No messing with the report rdl file.

Wednesday, March 7, 2012

CRM 2011: Report cannot be displayed

If you are getting the following error while trying to run a CRM 2011 out of the box report:

Full Stack: [ReportServerException: Immediate caller DOMAIN_NAME\executionAccount has insufficient privilege to run report as user S-1-5-21-1842424028-......] 

[ReportServerException: Cannot create a connection to data source 'CRM'. (rsErrorOpeningConnection)] 

OBS: For this scenario, I am considering that you have the SSRS server installed on a different server.

Here are some of the things you can try:

SCENARIO 1: You only have CRM 2011 reports in your SSRS reporting server: 
  1. In Reporting Service Configuration Manager, uncheck the 'Specify an Execution Account'. 
  2. Browse to both SharedReports\5.0.xxx\ and _MSCRM report folder and make sure that MSCRM_DataSource connection Data Source Type is set to Microsoft Dynamics CRM Sql and the connection is using the Credentials Supplied by the User running the report (uncheck the Windows Credentials box).
 SCENARIO 2: SSRS is in a shared environment, where the execution account needs to be used:
  1.  Add Execution Account to CRM's PrivUserGroup in AD. 
You can obtain more information here:
The Report Cannot be displayed RsProcessingAborted CRM 2011

Add Execution Account to PrivUserGroup


Thursday, August 11, 2011

CRM 2011: Using the LoseOpportunityRequest request

private void LoseAllOpportunitiesForCustomerId(Guid customerId, IOrganizationService _service){
 // Instantiate an organization context so that we can use LINQ queries
 var orgContext = new YourOrganizationContext(_service);
 // Build query to retrieve the related opportunities (w/Active statecode)
 var opportunityIds = from o in orgContext.OpportunitySet
    where o.CustomerId.Id == customerId && o.StateCode.Value == OpportunityState.Open 
    select o.OpportunityId.Value;

 foreach (var opportunityId in opportunityIds) {
  System.Diagnostics.Debug.WriteLine("Inactivating Opportunity Id: {0}.", opportunityId);

  OpportunityClose oppClose = new OpportunityClose();

  // Set the opportunityclose activity subject.
  oppClose.Subject = "Inactive customer.";
  // Create an entity reference to the opportunity being lost.
  oppClose.OpportunityId = new EntityReference(Opportunity.EntityLogicalName, opportunityId);
  // Create the LostOpportunityRequest request.
  LoseOpportunityRequest loseOppReq = new LoseOpportunityRequest();
  loseOppReq.OpportunityClose = oppClose;
  loseOppReq.Status = new OptionSetValue(-1);
  // Execute the request.
  _service.Execute(loseOppReq);
 }
}