In case you have ever wondered or needed to know, here is how you get the ID of the current user using .NET (C# in this case):

var whoAmIResponse = (WhoAmIResponse)OrganizationService.Execute(new WhoAmIRequest());

var currentUser = new EntityReference(SystemUser.EntityLogicalName, whoAmIResponse.UserId);

Hi Everyone,

Registration closes for the Plug-in Development Workshop on Thursday so now is the time to register.

Eventbrite - Plug-in Development with Dynamics CRM (April)

 

Here are what some of my former students have to say:

I found Mitch Milam’s workshop to be a great way to jump-start my plug-in development. Besides presenting class material in such a way that it was easy to comprehend, Mitch also provided Visual Studio templates. These templates proved to be extremely useful because they take care of the necessary plumbing when writing plug-ins, speeding up the development time. Additionally, the labs we worked on in class covered real-life scenarios directly applicable to my day-to-day work. In fact soon after the workshop, I solved a business problem by building a plug-in that was based on one of the labs we worked on in class.

Natalya Pinsker, Baltimore, MD

   

Mitch’s Plug-in Development workshop helped me get out of the gate and a good way down the path of C# development for Microsoft Dynamics CRM – including both Plug-ins and Workflow Assemblies. Mitch is an excellent instructor who responds to all questions and helps people along at their own pace. I highly recommend this workshop for anyone who is looking to get into the Microsoft CRM development game. It will accelerate your process and save you more than enough time to pay for itself.

Aron F.

   

Your class was an eye opening experience. In addition to learning about Plug-In Development this class exposed me to so many other aspects of Microsoft Dynamics CRM that I was not aware of.

Marlon R. Joseph, Application Analyst III, Houston Baptist University

 

You may get more details about this workshop here.

Thanks, Mitch

I am holding another Dynamics CRM Plugin Development workshop this month. The goal of the class is for me to teach you everything I know about plugin development.

When: Monday, April 21st through Thursday, April 24th. 1:00pm – 5:00pm CST each day.

Where: Online

What: This is a hands-on workshop with each student provided their own virtual development environment for the duration of the class

Cost: $895 per person (multi-student discounts available)

Note: Due to the interactive nature of this workshop, it will be limited to 10 students.

Eventbrite - Plug-in Development with Dynamics CRM (April)

Note: Registration closes at 10:00pm CDT.

Agenda:

  • Plugin architecture and design
    • The Dynamics CRM execution pipeline
    • The how, why, and where of plugging into Dynamics CRM
    • Performance considerations
    • Working in the sandbox
  • The development environment
    • Setup
    • Source control
    • Working in teams
  • Deploying plugins
    • To CRM
    • In a solution
    • To CRM Online (if applicable to the student population)
  • Debugging plugins
    • Synchronous vs. asynchronous
    • Full-trust vs. sandboxed
  • Custom activity architecture
  • Design features
  • Deployment
  • Asynchronous process monitoring
  • System job cleanup and maintenance
  • Open-lab time
  • Upgrade scenarios
  • Code-recovery of lost source plugin code

Thanks to our virtual development environments, the majority of our time will be spent actually designing and developing real-world plugins. Think labs. Lots and lots of labs. In fact, here is the list:

Plug-In Exercises:

  • Exercise 1: Autonumber – DateTime
  • Exercise 2: Autonumber – QueryExpression
  • Exercise 3: Autonumber – SQL
  • Exercise 4: Create Related Records
  • Exercise 5: Generate a Formal Name
  • Exercise 6: Handling Exceptions
  • Exercise 7: Multi-Entity Plugin
  • Exercise 8: Monitoring Plug-In Depth
  • Exercise 9: Auto-Assign Records
  • Exercise 10: Zip Code Lookup
  • Exercise 11: Child Record Rollup
  • Exercise 12: Data Validation
  • Exercise 13: Audit Log

Custom Workflow Activity Exercises:

  • Exercise 1: Route a New Lead
  • Exercise 2: Verify Email

In addition to the workshop materials, each student will receive additional tools and code templates to help increase their productivity as a Dynamics CRM plug-in developer.

Finally, all students are free to keep any work produced during their lab-time as well as the tools and templates used in class.

Every now and then I run into an issue that I should have already known about.  Either that, or I knew about it and later forgot.  Regardless, let me tell you the story of the plug-in and the missing data.

 

Background

Let us say that I have a plug-in that is registered on the Create message for the Account entity. When a new Account is created, it will automatically populate a custom field with the name of the Primary Contact using code that looks like this:

var primaryContact = entity.GetAttributeValue<EntityReference>("primarycontactid");

entity["new_primarycontactname"] = 
    string.Format("{0}-{1:d}", primaryContact.Name, DateTime.Now);

This is pretty simple CRM SDK work that most of us do on a daily basis without much thought whatsoever.  All I am doing is taking the display name from the Entity Reference and using that value, along with the current date, to populate my custom field.

When the record is created with the CRM user interface, this code works perfectly. But, and there is always a but, what if we create the Account using an SDK call?

The answer is: It does not work so perfectly.

When you are creating an Entity record using the SDK the common method for creating an Entity Reference is to use code like this:

entity["primarycontactid"] = new EntityReference(Contact.EntityLogicalName, 
                                      Guid("9C06869F-50C6-E211-8D6B-00155D1E5005"));

This is the minimum requirement for populating an Entity Reference (Lookup) field using the SDK, and is generally how everyone does it.

 

The Problem

The problem is our plug-in.  Since the plug-in is registered on the Create message, it will fire for each Account being created, no matter if the record is coming from the Dynamics CRM web client, from a Scribe or SSIS job, or in this case, from a customer-facing web portal.

Since we did not specify the .Name property on our primarycontactid field, it will arrive inside of the plug-in as a Null value.

This means my plugin code will produce: "-4/8/2014” instead of “John Smith-4/8/2014.

This is not a bug in CRM, this is just the way it works.

 

The Work Around

So if we indeed need the .Name property on the Entity Reference, we need to either specify it in our code, like this:

var primaryContact = new EntityReference(
                              Contact.EntityLogicalName, 
                              new Guid("9C06869F-50C6-E211-8D6B-00155D1E5005"));
primaryContact.Name = "John Smith";

entity["primarycontactid"] = primaryContact;

OR, and this is not exactly a good thing, perform a read, from within the plug-in, of the Entity record referenced and pull back the primary field, like this:

var contact = organizationService.Retrieve(
                 patientReference.LogicalName, 
                 patientReference.Id, 
                 new ColumnSet(new[] { "fullname" }));

return patient["fullname"].ToString();

Anyway, this is something to keep in mind should you have an applications integrated with your Dynamics CRM system.

Hi Everyone,

Next month I will be holding two workshops for CRM developers:

 

Plug-in Development with Dynamics CRM

Monday, April 21th through Thursday, April 24th. 1:00pm-5:00pm each day.

 

JavaScript Development with Dynamics CRM

Monday, April 28th through Thursday, May 1st. 1:00pm-5:00pm each day.

 

Pricing

Pricing will be $895 per student, per workshop, with multiple-student and multiple-workshop discounts available.

Due to the interactive nature of the workshop, there is a limit of 10 students per workshop.

 

Registration

Registration will open on Thursday, April 3rd.

To pre-register and secure your seat now, enter your information on the April Workshops sign-up page.

Hi Everyone,

I have just released version 2.6 of my JavaScript conversion tool: Transformer! for Dynamics CRM.

You may read more about the update here.

Thanks, Mitch

Hi Folks,

The registration deadline for next week’s workshop: JavaScript Development in Dynamics CRM

ends on January 23rd at 12:00pm CST.

For more information and to register, visit:

http://www.infinite-x.net/2014/01/17/next-weeks-workshop-javascript-development-in-dynamics-crm

In the first article we discussed using SQL to determine the size of the Attachments in the database.

My friend Aron Fischman shared with me similar queries using FetchXml:

 

<!--Email Attachment File Size Analysis-->
<fetch distinct='false' mapping='logical' aggregate='true'> 
  <entity name='activitymimeattachment'> 
    <attribute name='activitymimeattachmentid' alias='EmailAttachmentCount' aggregate='count'/> 
    <attribute name='filesize' alias='FileSizeSum' aggregate='sum'/> 
    <attribute name='filesize' alias='FileSizeAvg' aggregate='avg'/>
    <attribute name='filesize' alias='FileSizeMax' aggregate='max'/> 
    <attribute name='filesize' alias='FileSizeMin' aggregate='min'/> 
  </entity> 
</fetch>

<!--Annotation File Size Analysis-->
<fetch distinct='false' mapping='logical' aggregate='true'> 
  <entity name='annotation'> 
    <attribute name='annotationid' alias='AnnotationCount' aggregate='count'/> 
    <attribute name='filesize' alias='FileSizeSum_bytes' aggregate='sum'/> 
    <attribute name='filesize' alias='FileSizeAvg_bytes' aggregate='avg'/>
    <attribute name='filesize' alias='FileSizeMax_bytes' aggregate='max'/> 
    <attribute name='filesize' alias='FileSizeMin_bytes' aggregate='min'/> 
  </entity> 
</fetch>

I am very excited to announce that my workshop on Dynamics CRM JavaScript Development is now ready. The goal of the class is for me to give you a very thorough introduction to using JavaScript within Dynamics CRM.

After a good deal of consideration, I have decided to take the normal two days of instruction and split it into four days of four hours each.  This should allow students time to better absorb the material as well as get their normal work accomplished.

Here are the specifics:

When:
Session 1
: Monday, January 27th through Thursday, January 30th. 7:00am-11:00am each day.

Register for Session 1

 

Session 2: Monday, January 27th through Thursday, January 30th. 1:00pm-5:00pm each day.

Register for Session 2

 

Where:
Online using GoTo Meeting.

What:
This is a hands-on workshop with each student provided their own virtual development environment for the duration of the class.

Cost:
$895 per person (multi-student discounts available)

 

Note: Due to the interactive nature of this workshop, it will be limited to 10 students.

Student Prerequisite Knowledge:

  • Each student must have working knowledge of Dynamics CRM 2011.
  • Knowledge of JavaScript is also required.

Note: For those students that have not worked with JavaScript previously, a short introduction webinar will be conducted on Friday, January 24th. Students attending this webinar will be expected to have completed the accompanying self-study materials before Monday's class begins. Everyone must be ready to run on Monday for the main class.

 

Agenda:
Each classroom day will be four hours in length, with the virtual environments available for student use all day, until midnight of January 30th.

And thanks to our virtual development environments, the majority of our time will be spent actually developing JavaScript solutions for Dynamics CRM.

Think labs. Lots and lots of labs. And homework. There will be homework.

We'll cover the following topics:

  • Creating a development environment
    • Setup
    • Source control
    • Working in teams
    • Working with Visual Studio
  • Working with Web Resources
  • Working with Solutions
  • Working with Forms
    • JavaScript libraries
    • Form events
    • Form Event Handler Execution Context Reference
  • Working with the Xrm.Page Object Model
    • Working with Collections
    • Data operations
    • Tabs and Sections
    • Working with Controls
    • Working with iFrames
    • Working with Navigation Items
  • Ribbon button and JavaScript connection
  • Opening Dynamics CRM Forms and Web Resources via JavaScript
  • Using the XrmSrcToolkit to CRM-related data operations

We will be using about 75 of the methods found in the Xrm.Page object model so you should leave class with a fairly good understanding of where things are and how to access them.

If we have time, we will also cover some of the freely available JavaScript components that can be used to aid in your development efforts and to increase your user's productivity.

Students will also receive a draft copy of my upcoming book on Dynamics CRM JavaScript development along with sample code and utility web resources that should help you kick start your CRM JavaScript development efforts.

 

Please email me if you have any questions: mitch at crmaccelerators dot net

I’ve extended the registration for next week’s webinar until 10:00pm CST.

See this post for more information: December Training: Dynamics CRM Plug-In Development

Don’t miss out on the finally workshop of the year.

Sign up for our new KnowledgeBits service and get news, tips and tricks and more, delivered straight to your inbox.