Navigation

Entries by TheCRMBook.com (21)

Thursday
Jan272011

Book update CRM 2011

As I’ve been traveling around the world doing training events on CRM 2011, a lot of people have been asking about an update on the book and what our plans are for CRM 2011. In addition to being crazy busy with all the things leading up to the launch we have also been busy working on updating content for CRM 2011. We currently have two CRM 2011 books planned for release in the next few months and I wanted to share a little bit of information on the plans.

clip_image001

Using Silverlight with CRM 2011 – Target Release March 2011

One of the cool new things in CRM 2011 is its support for making Silverlight a first class way to extend the user experience. This book will focus on all the different ways you can extend CRM 2011 using Silverlight including on Forms, on the Dashboard and many other creative ideas. The book also includes enough basic Silverlight information so if you are new to Silverlight you can get started right away.

clip_image002

CRM 2011 as a Rapid Development Platform – Target Release May 2011

A lot has changed since 2008 when the book was first published for CRM 4.0. At the same time, CRM 2011 is even more compelling for building a wide variety of applications that aren’t just limited to CRM. In this update to the popular CRM 4.0 book we will be focusing on providing deep information that developers need to build applications with CRM 2011 and the xRM Application Framework.

In both cases stay tuned if you have purchased our prior books we want to make sure you also get some special offers for the new books as well. If you don’t have one of our books, make sure you register on the book site as a user – http://www.thecrmbook.com

For anyone that might be interested we are also in need of a small number of people to provide early reviews and feedback on the content. Ideally, this would be a mix of people who are new to the topics and some that have been heavily involved in CRM 2011 beta testing. If that is you and you are interested please contact me directly via my blog at http://crm.davidyack.com/send-me-e-mail/

Wednesday
Jun022010

Old SDK – New SDK Query by OwnerId

The latest update to the MSCRM SDK included a new LINQ provider. In this blog post we are going to compare and contrast querying for data by owner ID using the old and new SDK techniques. If you are new to the LINQ provider then you should read my quick start blog post here first.

For this example let’s assume I want to retrieve accounts where the owner ID is the current user. The following is straight from the CRM SDK and uses the lower level API calls. Keep reading past it and I will use the new LINQ provider to accomplish the same thing plus a little bit.

Guid principalId = user.UserId;

// Create a column set holding the names of the columns to be retrieved.

ColumnSet colsPrincipal = new ColumnSet();

// Set the properties of the column set.

colsPrincipal.Attributes = new string[] { "name", "accountid" };

// Create a ConditionExpression.

ConditionExpression conditionPrincipal = new ConditionExpression();

// Set the ConditionExpressions properties so that the condition is true when the

// ownerid of the account equals the principalId.

conditionPrincipal.AttributeName = "ownerid";

conditionPrincipal.Operator = ConditionOperator.Equal;

conditionPrincipal.Values = new object[1];

conditionPrincipal.Values[0] = principalId;

// Create the FilterExpression.

FilterExpression filterPrincipal = new FilterExpression();

// Set the properties of the FilterExpression.

filterPrincipal.FilterOperator = LogicalOperator.And;

filterPrincipal.Conditions = new ConditionExpression[] { conditionPrincipal };

// Create the QueryExpression.

QueryExpression queryPrincipal = new QueryExpression();

// Set the properties of the QueryExpression.

queryPrincipal.EntityName = EntityName.account.ToString();

queryPrincipal.ColumnSet = colsPrincipal;

queryPrincipal.Criteria = filterPrincipal;

// Create the request object.

RetrieveMultipleRequest retrievePrincipal = new RetrieveMultipleRequest();

// Set the properties of the request object.

retrievePrincipal.Query = queryPrincipal;

Now that we have looked at how we would have done this in the past, let’s look at what is possible using the new LINQ provider. First, you should have already read my other blog post where I talked about how to call Who Am I to get the current user ID here. For this example we startup assuming that has already been accomplished.

To make this a little more interesting, in addition to just retrieving the accounts for the user I also want to retrieve the user’s name and only the first 10 accounts.

The first thing we are going to do is build the LINQ expression that will provide the criteria for our query. The following queries for accounts that have an owner ID matching. It also shapes the results into an anonymous type that only has the properties ID and Name. Pause for a second and compare the following 7 lines, which could really be expressed as 1 line to the code we used above without the LINQ provider.

var principalQuery = from acct in ctx.accounts

where acct.ownerid.Value == currentUserID

select new

{

ID = acct.accountid,

Name = acct.name

};

Remember, the above just defines the LINQ expression it doesn’t cause execution of the query against the CRM server that will happen later when we start to enumerate the results. Next, let’s go get the user information so we can grab the full name of the user.

var userInfo =

ctx.systemusers.Where(u => u.systemuserid == currentUserID).FirstOrDefault();

If we retrieved a user the output the user name.

if (userInfo != null)

Console.WriteLine("First 10 Accounts for user " + userInfo.fullname);

Next, we are going to enumerate the accounts and print the account name. Notice that we added a Take(10) onto the LINQ query we built earlier. This will cause only the first 10 records to be used.

foreach (var acct in principalQuery.Take(10))

Console.WriteLine(" Account Name :" + acct.Name);

Hopefully it’s clear from the example the new CRM LINQ provider that’s part of the updated SDK makes it much easier to build queries against the CRM data.

Thursday
May132010

Using the CRM Service via the DataContext

Last week Microsoft announced the latest update to the MSCRM SDK that included a new LINQ provider. If you are new to the provider then you should read my quick start blog post here first.

In this blog post we are going to look at how you can use the CRM Service when you have a DataContext instance. As you probably recall the DataContext is generated when you run crmsvcutil against your CRM organization. DataContext is a wrapper on top of the standard CRM Service. Sometimes you need to drop down to make calls against the lower level CRM Service. For example, calling Who Am I, working with metadata and any other interaction that requires calling Execute. As it turns out if you have an instance of DataContext it provides an easy way to interact with the standard CRM Service for these types of operations. In the rest of the blog post we are going to look at calling WhoAmI using the DataContext helper methods.

The first approach we are going to look at is using the CreateService method on the DataContext. This method gives back an object instance that implements IOrganizationService. The IOrganizationService interface is a new abstraction as part of the updated SDK that provides methods to interact with both the transactional data in CRM and the metadata. Using the object instance returned from CreateService you can do calls to Execute just like you would from the CRM Service or Metadata Service directly.

Let’s get started making a Who Am I call to the CRM Service using the IOrganizationService instance. The first thing we need to do is add a using for the SdkTypeProxy namespace where the WhoAmIRequest/Response classes reside. Notice we are using an alias of SdkTypeProxy on the using. The reason for that is that name space also contains the “account” entity class and it conflicts with the generated account class created by CrmSvcUtil code generation. By using an alias we can work around this pretty easily.

using SdkTypeProxy = Microsoft.Crm.SdkTypeProxy;

Next, create an instance of the DataContext, remember this class is generated when you ran CrmSvcUtil and might have a different name if you chose something different on the options.

DataContext ctx = new DataContext("mycrm");
Next, define a Guid variable to hold the current user ID we get back.

Guid currentUserID = Guid.Empty;
Next, call the CreateService method on the context to get an instance of IOrganizationService. You will notice a couple of things in the following example. First, we are using “var service” without defining the type. The var keyword causes the type to be inferred from the right side of the statement. In this case it will be inferred to be IOrganizationService since that is what CreateService returns. We are using this approach to keep the code simply and concise without any redundant specification. You will also notice we wrap the code block with a “using”. When coded like below the using ensures that the dispose is properly called on the IOrganizationService instance when it falls out of scope either due to normal completion or an exception. We then proceed to build up a WhoAmIRequest object and call the execute method to get the current user ID.

using (var service = ctx.CreateService())

{

var userRequest = new SdkTypeProxy.WhoAmIRequest();

var user = service.Execute(userRequest) as SdkTypeProxy.WhoAmIResponse;

Console.Write("You are running as user " + user.UserId);

currentUserID = user.UserId;

}

The new SDK also offers another approach that you can use to accomplish the same thing. Instead of calling CreateService you can call the UsingService method which accomplishes the same thing as the “using” statement and the CreateService method call. The following is the revised code adjusted to call the UseService method.

ctx.UsingService(service =>

{

var userRequest = new SdkTypeProxy.WhoAmIRequest();

var user = service.Execute(userRequest) as SdkTypeProxy.WhoAmIResponse;

Console.Write("You are running as user " + user.UserId);

currentUserID = user.UserId;

});

Using either approach you can make calls to the standard CRM Service without having to re-create a connection to the CRM server using the lower level API. Stay tuned as we continue to explore how to use the new LINQ provider that is part of the new SDK.

Monday
Mar092009

XRM Virtual is about to take off....

NEW XRM Virtual User Group

We all know I have a thing with helping our professional community. We also all know I am easily bored and easily distracted by shiny things. Add those together and some pretty cool things can happen.

XRM Virtual User Group is un-officially open for business.

A while back, several months ago, I had been receiving emails from our book readers (thecrmbook) with questions about how to use XRM. I loved the fact that the book gave them loads of info, but they all seemed to be wanting more. Not that the book was missing anything, but more that the book inspired more of them.

A couple of weeks ago, I was introduced to Shan McArthur again. He is my new hero. He was preparing his sessions for Convergence this week and had this cool tool. The tool looked good and knowing I was brewing this group in my head for a while, I mentioned it to him, more as an opportunity for him to join than anything else. He came back with a sweet offer. Let me build this site for you, using our cool XRM solution AND demo it at Convergence in front of your target audience. How could I say no?? I would have been crazy. His team has plugged away and made us a great site, using the very technology we are preaching about.

 

Thanks go out to Ben Riga for pushing this through and getting us our CRM Online credentials so quickly. And thanks to my husband David Yack for his book that got this inspiration off the ground and his work helping us get off the ground (and putting up with manic wife for a couple weeks).

 

(We will be an official INETA group very soon)

Press Release here

Thursday
Feb262009

CRM Incubation week #2 just announced

So directly or indirectly we have all been hit by our "economic downturn" (I hate that phrase!). Maybe you got a cut in hours, lost your job altogether or had your credit card company suddenly reduce your credit limit. Right?

 

So with all that mess going on around us we need to seek out community opportunities to help build our skills and our business. These events are of such great value, you would pay for them, but they're free! Yup, FREE.

 

So, my buddy Sanjay had such a great success with the first CRM Incubation week, that he is doing another one. This one in Boston, week of April 20. Only cost you need to cover is your travel to/in Boston. Rest is free. Training. Industry experts. Angel investors hanging around.

Pretty cool stuff going on here. More details below on Sanjay's blog. Tell him Julie sent you :)

 

Microsoft Dynamics ISV Architect Evangelism : Startups: Announcing 2nd Microsoft Dynamics CRM Incubation Week