CRM 2011 – OptionSetValue returned in LINQ only returns int value

I was using LINQ to retrieve multiple rows and I am loving that but I was doing a linq query to get the different address for an account.

This worked fine except I wanted to check the address type by name.  So I wanted to retrieve the Primary address.  I found out that in LINQ, optionsetvalues only return the int number value and not text/label.  To get the label you have to look it up using the metadata service.  ARGHGHGHG how frustrating.  I was searching OptionSetValue, metadata search and couldn’t find anything for ages until I saw that the samples has a couple of projects all about metadata calls.

You can find them here

it was annoying at the time because I had just figured out how to return the values in LINQ and I didn’t want to hard code the values to the int optionSet values because I thought it wouldn’t work if someone added in new address types but it wouldn’t still work if I used the address type string name.
Microsoft.Xrm.Sdk.Client.OrganizationServiceContext orgContext =                           new Microsoft.Xrm.Sdk.Client.OrganizationServiceContext(_service);
IEnumerable<CustomerAddress> addresses = from c in orgContext.CreateQuery<CustomerAddress>()                                                             join aa in orgContext.CreateQuery<Account>() on c.ParentId.Id equals aa.Id

where (c.ParentId.Id == new Guid(“92eb0d0e-b22e-e011-9645-00155d106b02”))

select c;

 

System.Console.WriteLine(“========================”);

foreach (CustomerAddress ca in addresses)                    {

System.Console.WriteLine(ca.AddressTypeCode + ” ”

+ ” ” + ca.CustomerAddressId
+ ” ” + ca.AddressTypeCode.Value

+ ” ” + ca.Line1

+ ” ” +  ca.Line2

+ ” ” + ca.Line3);

OptionSetValue opp = ca.AddressTypeCode;

System.Console.WriteLine(” ” + ca.CustomerAddressId.Value);

}

Advertisement

CRM 2011 – You can Delete business units

One thing I have always found a little bit odd about Microsoft’s Dynamic CRM is once you have made a new field, business unit and many other things you cannot change value’s on it.

I’m not entirely sure what goes on in the background and what is setup but clearly the name of the variable is used to setup security or privledges, it must be the name rather than the ID because you cannot change it.  It doesn’t seem like good practise to me but its where we are.

in CRM 4, once you created a business unit you could never get rid of it, so you better not misspell it.

But CRM 2011 allows you to delete the business unit, not that I have been deleting any business units but I did read it in the latest Customer Effective Blog

Say Goodbye to Abandoned Business units in CRM 2011

This is one of those useful changes to know but I hadn’t seem mentioned anywhere.

The customer Effective Blog for those who aren’t subscribed to it is a great source of interesting and useful CRM information

Microsoft Executive Interview – Trends in CRM over the last 10 years

I saw an interesting interview on Software Advice’s blog.  This is the first interview of a week of interviews.  You can go to the blog here to check it out directly

The interview takes place in Redmond, Washington and in this interview they ask Brad Wilson, General Manager of CRM Dynamics his thought on the state CRM.

He make an interesting observation, he puts forward the idea that CRM systems have moved from optional to a something businesses need to take advantage of be on top of, otherwise they run the risk of falling behind their competitors.

The other main point I took from the video is Brad thinks the biggest obstacle with the success or failure of CRM systems over the last 10 years is users rejected the CRM system.  Either not liking the solution or finding it difficult to use and customize to their needs.  This is one area Microsoft CRM dynamics is quite strong, it has a good solid base platform but has put a lot of effort to make it easier (especially in 2011) for you to customize the CRM solution.

Lastly he points out that CRM systems are becoming more popular because they are cheaper.  I think competition and particularly from Microsoft is pushing this point.

The video was an interesting snippet and tomorrows should also be interesting because it has the title – Will Microsoft Dynamics CRM 2011 slow Salesforce?

Here is the video

CRM 2011 – How to use guids in LINQ queries

This took me a bit of time to work out but in the end it’s very simple.  You can’t just reference a guid as a string, you have to create a guid type or cast it to be a guid.  Amusingly I had to select the guid to make find out what the guid was which totally defeats the object but I wanted to know what it was.

In the end it turned out my initially code didn’t work because I had missed a digit off, .NET to be fair did tell me my guid need to be 32 digits.

Create a guid

Guid myGuid = new Guid(“92eb0d0e-b22e-e011-9645-00155d106b02”);                             IEnumerable<Account> accounts = from a in orgContext.CreateQuery<Account>()

where (a.Id == myGuid)

{

Name = a.Name,

Address1_County = a.Address1_County,

Id = a.Id

};

Casting the String to a guid

IEnumerable<Account> accounts = from a in orgContext.CreateQuery<Account>()

where (a.Id == new Guid(“92eb0d0e-b22e-e011-9645-00155d106b02”))

{

Name = a.Name,

Address1_County = a.Address1_County,

Id = a.Id

};

Visual Studio 2010 and .NET Framework 4 Training Kit

For people studying for the 70-515 – Web Applications .NET 4 exam.   You will need to know a Ajax, MVC 2, ASP.NET controls.

Microsoft have rather nicely created some training courses, which you can find here

The training course focuses on Visual Studio 2010 and .NET 4.  This is a lot of the areas covered in the exam.

here are the units covered in the course

Units

OverviewIn this introductory unit, the Visual Studio 2010 and .NET Framework 4 evangelism team welcomes you to the training course and goes over the significant changes to Visual Studio 2010 and the .NET Framework 4. We’ll also cover what you’ll see in the course and how to follow along with the labs.

 

Managed LanguagesThere are same great enhancements to the set of managed languages in Visual Studio 2010. Not only do C# and Visual Basic continue to evolve together as premier languages in Visual Studio, but we also added a new functional programming language called F#.

 

ASP.NET 4In this unit, we’ll cover the enhancements to ASP.NET in the .NET Framework 4. You’ll learn about changes to WebForms, AJAX and Dynamic Data and you’ll get introduced to ASP.NET MVC, now included in the framework.

 

Data PlatformAlmost every application needs to interact with data. In this unit, you’ll learn about the enhancements to the .NET Framework’s data access technologies including ADO.NET Data Service, ADO.NET Entity Framework and Microsoft Distributed Cache.

 

Windows Communication Foundation and WorkflowWindows Communication Foundation and Workflow are significantly improved in the .NET Framework 4. In this unit, you’ll learn about the improvements to both as well as the integration of the two which make it easy to expose Workflows as services.

 

Parallel ComputingParallel computing is an important focus in the .NET Framework 4 as developers create applications that can take full advantage of multi-core processors. In this unit, you’ll learn about the new additions to the .NET Framework to make developing parallel code easier.

 

Application Lifecycle ManagementVisual Studio 2010 includes a first-class set of Application Lifecycle Management tools. In this unit, we’llcover several of the new ALM features in Visual Studio 2010

 

CRM 2011 – Quick way to find a guid using a CRM form

Sometimes when I am coding I need the guid of an account, contact etc so I can put it in my code and retrieve one account.

The quickest way I have found to get this from CRM is to go into the account form or the form you want the guid from.

Then press F11, this will maximise the screen.  It also shows the url bar at the top.  You can then

http://crmdevmscrm/Demo/main.aspx?etc=1&extraqs=%3f_gridType%3d1%26etc%3d1%26id%3d%257b92EB0D0E-B22E-E011-9645-00155D106B02%257d%26rskey%3d246505345&pagetype=entityrecord

The guid is the bit after ID and up to the %26

id%3d%257b92EB0D0E-B22E-E011-9645-00155D106B02%257d%26

the b%3d%257 is the first curly bracket { and the %257d%26 is the closing curly bracket, take those out and you are left with the guid

92EB0D0E-B22E-E011-9645-00155D106B02