Monday, December 20, 2010

Two ways to build a CRM QueryExpression

I always wondered what FetchXML was useful for and I’m starting to see its value.  I ran into a wall with the new Linq based Advanced Developer Extensions and have reverted back to the “stone-age” web services.  Having to build QueryExpressions by hand led me to the discovery that I could actually use FetchXML syntax to build my expressions by using a FetchXmlToQueryExpressionRequest Combining this with Stunnware’s FetchXML builder might be even faster once you get the hang of it.  Certainly makes debugging a complex join query snappy.

 

Check out these two ways to get the exact same dataset:

 

        private static void FetchAppsToProcess(Microsoft.Crm.SdkTypeProxy.CrmService crmWebSvc)

        {

            string fxml =

                @"<fetch mapping='logical' count='50' version='1.0'>" +

                " <entity name='new_transistionapplication'>" +

                "       <attribute name='new_transistionapplicationid' />" +

                "       <filter>" +

                "             <condition attribute='createdon' operator='lt' value='9/17/2010' />" +

                "             <condition attribute='new_lastname' operator='eq' value='Smith' />" +

                "       </filter>" +

                " </entity>" +

                "</fetch>";

 

            //string xmlResult = crmWebSvc.Fetch(fxml);

            FetchXmlToQueryExpressionRequest fxmlReq =

             new FetchXmlToQueryExpressionRequest() { FetchXml = fxml };

            FetchXmlToQueryExpressionResponse expression =

             (FetchXmlToQueryExpressionResponse)crmWebSvc.Execute(fxmlReq);

 

            var request = new RetrieveMultipleRequest { Query = expression.Query, ReturnDynamicEntities = true };

            var response = (RetrieveMultipleResponse)crmWebSvc.Execute(request);

 

        }

 

        private static void GetAppsToProcess(Microsoft.Crm.SdkTypeProxy.CrmService crmWebSvc)

        {

            List<string> reqBoards = new List<string>();

 

            var con = new ConditionExpression

            {

                AttributeName = "createdon",

                Operator = ConditionOperator.LessThan,

                Values = new object[] { DateTime.Parse("9/17/2010") }

            };

 

            var conName = new ConditionExpression

            {

                AttributeName = "new_lastname",

                Operator = ConditionOperator.Equal,

                Values = new[] { "Smith" }

            };

 

            var filter = new FilterExpression();

           

            filter.AddCondition(con);

            filter.AddCondition(conName);

            filter.FilterOperator = LogicalOperator.And;

           

 

            // The Entity returning the results

            var expression = new QueryExpression

            {

                EntityName = "new_transistionapplication",

                Criteria = filter

            };

           

            expression.ColumnSet = new ColumnSet(new string[] { "new_transistionapplicationid", "new_requestedboardappointments" });

 

            var request = new RetrieveMultipleRequest { Query = expression, ReturnDynamicEntities = true };

            var response = (RetrieveMultipleResponse)crmWebSvc.Execute(request);

        }

Friday, December 17, 2010

Installing SSRS - SocketException: No such host is known

I just about went crazy trying to do a SSRS install on a named instance.  Every time I ran through the database configuration, I got this error.

System.Net.Sockets.SocketException: No such host is known

   at System.Net.Dns.GetAddrInfo(String name)

   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)

   at System.Net.Dns.GetHostEntry(String hostNameOrAddress)

   at ReportServicesConfigUI.RSDatabase.IsLocalDbServer(String dbServer)

   at ReportServicesConfigUI.RSDatabase.GrantRSConnectionRights()

   at ReportServicesConfigUI.RSDatabase.CreateNewDatabase()

Turns out, this issue has a simple, but hidden workaround.  Specify the Server Name as outlined on this blog post:

 

It seems if you use a connection format like “ServerName\InstanceName,Port”, then SSRS Configuration manager is able to connect without requiring the SQL Browser service.

 

Without SQL Browser service running (either shutdown or blocked behind the firewall), SSRS Configuration Manager still does not work with “ServerName,Port\InstanceName” format or via SQL Aliases.

 

Tuesday, December 14, 2010

Daddy Bread

After reading the article, Artisian Bread in Five Minutes a Day, I have been making about 1-2 loaves and a pizza every week.  My kids have dubbed it, “Daddy bread” and it goes fast!  As you might imagine we go through a decent amount of flour, so we buy 25lbs bags at Costco.  This picture of six coffee cans is the latest supply of flour.  I can almost smell the bread cooking!

Monday, December 13, 2010

How to Hide System Views in CRM 4.0

This post could also be titled, how to pass configuration to CRM Plugins.  I found a sample solution in the MSDN Code Gallery but the installation details were left to the imagination.  Fortunately another person posted on how to hard-code a plugin with the Assembly Registration information needed.  First you register the assembly, then add a step with this information:

 

Message: RetrieveMultiple
Primary Entity: savedquery
Stage of Execution: Post Stage
Execution Mode: Synchronous

Unsecure Configuration: <the XML from the sample config file>

 

There was a problem with the code from the gallery in that the constructor for plugins seems to have changed.  Plugin constructors require two string parameters as detailed in this blog post.  The first is the “unsecure configuration” and the second is the “secure configuration”.

 

The nice thing is that the views are hidden as soon as you “Update” the Step Registration.  No need to restart CRM or anything fancy. 

 

You can download the source of my plugin here (6 Kb zip) (you may have to update the references to the SDK dlls).

Thursday, December 2, 2010

How to set a recipient in the CRM Send Email window via URL querystring

I need to let the user edit the email before sending, so email templates seem to be the best choice.  I love how CRM set the Regarding to my current entity.  In addition I wanted to be able to set the To: field based on a contact record.

 

MSDN - URL Addressable Forms and Views

and here:

Working With All MS CRM DataTypes In Javascript

and ultimately, I figured out the querystring parameters that allow you set a PartyList attribute (To is a PartyList - thanks to Stunnware tool for that detail).  So by adding these parameters to the original Send E-Mail link, the email opens pre-populated:

&partytype=2&partyname=John%20Doe&partyId={1FF3C7A9-D8BC-DF11-8337-005056BC7B56}