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

Communities
MSDN CRM Forums

Tools
PowerShell Tools
MscrmTools / XrmToolBox

CRMSvcUtil XrmServiceContext example:
CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /out:Xrm\Xrm.cs /url:https://myord.api.crm.dynamics.com/XRMServices/2011/Organization.svc /username:admin@myorg.onmicrosoft.com /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 OData is the fastest way:

HTTP://MyCrmServer/MyTenant/xrmservices/2011/organizationdata.svc/workflowset?$SELECT=NAME&$filter=substringof('MyCustomWorkflowActivityClassName',xaml)

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

SELECT DISTINCT wf.NAME 
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);
    xrm.SaveChanges();
}