Wednesday, October 14, 2015

Helpful links and information for CRM Developers

My collection of essential links and information for Dynamics CRM Developers

MSDN References
Linq query examples
MSDN Client-side programming reference
Developers guide to reports for CRM


MscrmTools / XrmToolBox

CRMSvcUtil XrmServiceContext example:
CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /out:Xrm\Xrm.cs /url: / /password:pass@word1 /namespace:Xrm /serviceContextName:XrmServiceContext

Saturday, September 26, 2015

Setting up RAID 1 on M5A78L Windows 7

My current Win7 Media Center PC has been running 24x7 for 3 plus years and the cruft on the OS was starting to really slow things down.  I figured it was time to re-install, but this time I wanted redundancy, so I bought two WD 160 drives to setup a RAID 1.  Here's the trick to setting this up in the ASUS Bios:

  1. On the SATA Configuration tab, select Ports 1-4 and change their mode to RAID (note this also changed 5-6 to RAID, so I needed to switch that back to IDE for my optical).
  2. Save and Reboot.  Wait for the RAID Bios screen to appear and hit CTRL + F
  3. In the RAID configuration, select the LD config and select LD 1 on the next screen
  4. In the LD details page, use SPACE to change value of RAID to 1 and select your drives. 
  5. CTRL + Y saves changes and then reboot and you're done!

Wednesday, July 29, 2015

Getting CrmSvcUtil to generate the CrmOrganizationServiceContext

It had been awhile since I generated the Early-bound classes used by a command-line setup program (MSFT walkthrough).  I had forgotten about the crmsvcutil.exe parameter that generates the CrmOrganizationServiceContext:
/codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration"

After adding the Microsoft.Xrm.Client.CodeGeneration.dll and Microsoft.Xrm.Client.dll to the directory,  the App.config constructor was available again:
using (XrmServiceContext xrm = new XrmServiceContext("Xrm"))

Tuesday, June 9, 2015

Dynamics CRM Publish External Report

Dynamics CRM on-prem has the ability to publish reports "externally" so that non-CRM users can view them.  Corresponding reports are created by CRM in the "root" folder (tenant name_MSCRM)  By default though, the SSRS data connection (MSCRM_DataSource) in the folder is not configured during installation, so a required step is to login to SSRS Report Manager and setup the data source.  Note, you have to click Details View (upper right corner of menu) in order to see the data source.

Typically, you'll want to use a service account that has the least privileges necessary to query the data from CRM.  The connection string follows the format:

Data Source=sql server;Initial Catalog=tenant_MSCRM

If you use a service account, you may get an error when you Test Connection in SSRS Report Manager:
Log on failed. Ensure the user name and password are correct.

In that case, the error may be caused because the account does not have "Log on locally".  

To grant this permission, do the following:
1.      On the report server computer, in Administrative Tools, open Local Security Policy.
2.      Under Security Settings, expand Local Policies, and then click User Rights Assignment.
3.      In the details pane, right-click Allow log on locally and then right-click Properties.
4.      Click Add User or Group.
5.      Click Locations, specify a domain or other location that you want to search, and then click OK.
6.      Enter the Windows account for which you want to allow interactive login, and then click OK.

7.      In the Allow log on locally Properties dialog box, click OK.

Wednesday, February 11, 2015

Find All References to a Custom Workflow Activity in Dynamics CRM 2013

If you ever need to find all the workflows that have references to a custom workflow assembly, you can query the Xaml column on the Workflow entity.  Using ODate is the fastest way:


If you are on-prem, then you can also do this via SQL:

FROM   workflow wf 
WHERE  xaml LIKE '%MyCustomWorkflowActivityClassName%' 

Tuesday, February 10, 2015

Stuck Dynamics CRM ImportJob importing a Solution

Did you know that you can view the progress of your import by using Advanced Find to query Import Jobs?  If you ever "lost touch" with the progress bar window, this can be very useful.  I have a saved view that displays the imports from the last 7 days in descending order.

Unfortunately, jobs can get stuck during import and prevent you from importing your solution again.  In that situation, you need to manually delete the stuck job.  Fortunately this is super easy with the Advanced Find you created above.  There is a special Delete button on this view.

You can also do it programmatically with the early-bound classes and a Linq query in the Service Context:

var xrm = new XrmServiceContext("Xrm");
var deadJobs = xrm.ImportJobSet.Where(x => x.CompletedOn.Equals(null));

foreach (var job in deadJobs)
    Console.WriteLine("Deleting Job Created On: " +job.CreatedOn);
    xrm.Delete(ImportJob.EntityLogicalName, job.Id);

Monday, November 17, 2014

CRM 2013 Invalid Argument FetchXML Report Errors on Premise

I love it when my former-self comes to the rescue of my present self.  I have been wrestling with an SSRS error that I knew I had seen before.  In searching for an answer, I ran across this blog post I wrote a couple years back.  I'm going to copy it here, just in case my former employer decides to take it down:

Even though the Report Wizard has some inherent limitations, it is still a useful tool for end-users that want ad-hoc reporting, or if you want to see beyond the 10,000 record limit when exporting to Excel.  You may find however that reports created by the Report Wizard return an "Invalid Argument" error. 
This happened to me recently so I followed my usual debugging steps but that did not help because the browser didn't return an error.  I checked the CRM and SSRS event logs, but there wasn't any helpful information in the errors that were logged.  Next I checked the SSRS HTTP Log and found some interesting information.  Note, the default location for the log is:
\Microsoft SQL Server\\Reporting Services\LogFiles
In the log I saw that I was getting a security error:
System.ServiceModel.Security.SecurityNegotiationException: A call to SSPI failed
When I looked up this error, I ran across KB2590774 which described the exact issue I was facing...unfortunately it involved SPNs; probably my least favorite administrative topic.
The instructions are a little contradictory.  It says that all you need to do is setup an SPN for the CRMAppPool...unless you are running IIS in Kernel Mode (generally the recommended configuration).  If running Kernel mode, you are supposed to review the information in the article about SPNs and IIS 7 Kernel Mode.
I read and confirmed that for my configuration (Scenario 2b - Custom app-pool and host header)the recommendation was to register an SPN for my custom URL on the NetBios name (aka, the computer name).  Unfortunately this did not resolve my issue, even after adding "trust for delegation" in AD.  So I tried the KB's recommendation which was an SPN for NetBios name on the CRMAppPool account:
setspn -s HTTP/my_server_name my_domain\my_CRM_app_pool_identity
After that SPN was applied (always using -S to check for duplicates) the FetchXML reports instantly started working!