24 November 2011

CRM 4 Entity Type Codes

The following table gives the entity type codes for each of the vanilla entities in Dynamics CRM 4:

Entity name

Value

Account

1

AccountLeads

16

ActivityMimeAttachment

1001

ActivityParty

135

ActivityPartyRollupByAccount

4603

ActivityPartyRollupByContact

4604

ActivityPointer

4200

Annotation

5

AnnualFiscalCalendar

2000

Appointment

4201

AttributeMap

4601

BulkImport

4407

BulkOperation

4406

BulkOperationLog

4405

BusinessUnit

10

BusinessUnitMap

6

BusinessUnitNewsArticle

132

Calendar

4003

CalendarRule

4004

Campaign

4400

CampaignActivity

4402

CampaignActivityItem

4404

CampaignItem

4403

CampaignResponse

4401

Commitment

4215

Competitor

123

CompetitorAddress

1004

CompetitorProduct

1006

CompetitorSalesLiterature

26

ConstraintBasedGroup

4007

Contact

2

ContactInvoices

17

ContactLeads

22

ContactOrders

19

ContactQuotes

18

Contract

1010

ContractDetail

1011

ContractTemplate

2011

CustomerAddress

1071

CustomerOpportunityRole

4503

CustomerRelationship

4502

Discount

1013

DiscountType

1080

DocumentIndex

126

Email

4202

EntityMap

4600

Equipment

4000

Fax

4204

FilterTemplate

30

FixedMonthlyFiscalCalendar

2004

ImportConfig

4408

Incident

112

IncidentResolution

4206

IntegrationStatus

3000

InternalAddress

1003

Invoice

1090

InvoiceDetail

1091

KbArticle

127

KbArticleComment

1082

KbArticleTemplate

1016

Lead

4

LeadAddress

1017

LeadCompetitors

24

LeadProduct

27

Letter

4207

License

2027

List

4300

ListMember

4301

MonthlyFiscalCalendar

2003

Opportunity

3

OpportunityClose

4208

OpportunityCompetitors

25

OpportunityProduct

1083

OrderClose

4209

Organization

1019

OrganizationMap

7

OrganizationUI

1021

PhoneCall

4210

PluginType

4602

PriceLevel

1022

PrincipalObjectAccess

11

Privilege

1023

PrivilegeObjectTypeCodes

31

Product

1024

ProductAssociation

1025

ProductPriceLevel

1026

ProductSalesLiterature

21

ProductSubstitute

1028

QuarterlyFiscalCalendar

2002

Queue

2020

QueueItem

2029

Quote

1084

QuoteClose

4211

QuoteDetail

1085

RelationshipRole

4500

RelationshipRoleMap

4501

Resource

4002

ResourceGroup

4005

ResourceSpec

4006

Role

1036

RolePrivileges

12

RoleTemplate

1037

RoleTemplatePrivileges

28

SalesLiterature

1038

SalesLiteratureItem

1070

SalesOrder

1088

SalesOrderDetail

1089

SavedQuery

1039

SemiAnnualFiscalCalendar

2001

Service

4001

ServiceAppointment

4214

ServiceContractContacts

20

Site

4009

StatusMap

1075

StringMap

1043

Subject

129

Subscription

29

SystemUser

8

SystemUserLicenses

13

SystemUserPrincipals

14

SystemUserRoles

15

Task

4212

Team

9

TeamMembership

23

Template

2010

Territory

2013

UnresolvedAddress

2012

UoM

1055

UoMSchedule

1056

UserFiscalCalendar

1086

UserQuery

4230

UserSettings

150

04 October 2011

CRM 2011 Ribbon XML

I've just spent the last day playing with the ribbon XML and have become increasingly frustrated. I have eventually got it working but I'm still no closer to understanding what I'm doing.

Any good articles/blogs would be greatfully received.

07 September 2011

CRM 2011 SDK 5.0.6 Released

The latest version of the CRM 2011 SDK (v5.0.6) was released on 29th August 2011. It can be downloaded from MSDN.

Some of the updates:

  • The plugin registration tool has added support for Windows Azure AppFabric Access Control Services (ACS) 2.0
  • A new tool for analysing plugin performance.
  • Updated Azure sample code readme documentation to explain the setup procedures.
  • VB.NET code samples.

For the full list of updates see the release history.

CRM 2011 SDK 5.0.6 Released

The latest version of the CRM 2011 SDK (v5.0.6) was released on 29th August 2011. It can be downloaded from MSDN.

Some of the updates:

  • The plugin registration tool has added support for Windows Azure AppFabric Access Control Services (ACS) 2.0
  • A new tool for analysing plugin performance.
  • Updated Azure sample code readme documentation to explain the setup procedures.
  • VB.NET code samples.

For the full list of updates see the release history.

19 August 2011

Unit Testing

I a recent post I showed how to unit test CRM 4 plugins. In the post I used Rhino.Mocks to mock the CRM interfaces and MSTest. Since then I've been doing some more "playing" with unit testing and I've stopped using MSTest, now I'm using NUnit instead.

There's a pretty good comparison between MSTest and NUnit on the "Musings of a Bare Bones Coder" blog (http://www.barebonescoder.com/2010/06/mstest-vs-nunit-with-visual-studio-2010-tdd/) so I'm not going into that here. As is said NUnit does suffer in that it has to be run outside of Visual Studio and the author suggests using TestDriven.Net (http://www.testdriven.net/), which is good but I've since found Visual NUnit 2010 which is a freebie on the MSDN Visual Studio Gallery (http://visualstudiogallery.msdn.microsoft.com/c8164c71-0836-4471-80ce-633383031099).

Using Rhino.Mocks, NUnit, and Visual NUnit 2010 seems to be exactly what the doctor ordered in terms of unit testing your code straight from Visual Studio.

I will block with some more details about these tools later.


16 August 2011

Test-Driven CRM 4 Plugin Development

So here I am getting on the Test-Driven Development bandwagon, so I'm getting on a few stops later than most but it's getting to the destination that counts right?

To start with I thought I'd cut my teeth on a CRM 4 plugin. In this example the plugin doesn't do anything except check the entity that it's being called from but it shows the steps.

As you're probably aware a CRM plugin depends on the CRM web service via the IPluginExecutionContext interface, so for proper unit testing we need to provide a "fake" implementation of the IPluginExecutionContext interface, this is known as "mocking" in automated unit testing.

There are probably different options for mocking but in this example I'm using the Rhino Mocks framework. Rhino Mocks is open source and can be downloaded from: http://builds.hibernatingrhinos.com/builds/Rhino-Mocks. Google provides loads of tutorials on Rhino Mocks, I'm not going to go into that here.

1. Create a new solution within Visual Studio and add a Class Library Project, this is for the plugin. Lets call it: UnitTestingPlugin

2. Delete the Class1.cs file that gets created by default.

3. Add references to microsoft.crm.sdk.dll and microsoft.crm.sdktypeproxy.dll.

4. Now right click on the project and add a new Class, lets call it: AccountPlugin.cs.

5. Open the new class and enter the code as follows:

using Microsoft.Crm.Sdk;


namespace UnitTestingPlugin
{
public class AccountPlugin : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
if (context.PrimaryEntityName != "account")
{
throw new InvalidPluginExecutionException("Plugin expects to run against account entity");
}
}
}
}
6. Now lets save the project and add Test project to the solution, we'll call this project UnitTestingPlugin.Test. The naming convention is the name of the main project with .Test at the end.

7. First things first, lets delete UnitTest1.cs which was created automatically.

8. If you expand the references of the test project you'll see that it includes the Microsoft.VisualStudio.QualityTools.UnitTestFramework reference. We also need to add the CRM references; microsoft.crm.sdk.dll and microsoft.crm.sdktypeproxy.dll.

9. Lets we need to add Rhino.Mocks.dll.

10. The reference to add is one back to the UnitTestPlugin project.

11. Now lets add a new class which we'll call; AccountPluginTest.cs.

12. Open the new class and add the following code:

using Microsoft.Crm.Sdk;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace UnitTestingPlugin.Test
{
[TestClass]
public class AccountPluginTest
{
///
/// This test method will ensure that an error is thrown if the plugin is fired from an unexpected record type, i.e. not an account record!
///

[TestMethod]
[ExpectedException(typeof(InvalidPluginExecutionException))]
public void TestWrongEntity()
{
MockRepository mocks = new MockRepository();
IPluginExecutionContext context = mocks.StrictMock();

DynamicEntity target = new DynamicEntity();
target.Properties["firstname"] = "James";
target.Properties["lastname"] = "Sullivan";

PropertyBag inputParameters = new PropertyBag();
inputParameters.Properties[ParameterName.Target] = target;

using (mocks.Record())
{
Expect.Call(context.InputParameters).Return(inputParameters).Repeat.Any();
//Set the PrimaryEntityName property to something other than account.
Expect.Call(context.PrimaryEntityName).Return("contact").Repeat.Any();
}

using (mocks.Playback())
{
IPlugin plugin = new AccountPlugin();
plugin.Execute(context);
}
}

///
/// This test will ensure that no error is thrown if the plugin is fired from an account record.
///

[TestMethod]
public void TestAccountEntity()
{
MockRepository mocks = new MockRepository();
IPluginExecutionContext context = mocks.DynamicMock();

PropertyBag inputParameters = new PropertyBag();
DynamicEntity target = new DynamicEntity();
target.Properties["name"] = "Orville Consulting Ltd";
inputParameters.Properties[ParameterName.Target] = target;

using (mocks.Record())
{
Expect.Call(context.InputParameters).Return(inputParameters).Repeat.Any();
Expect.Call(context.PrimaryEntityName).Return("account").Repeat.Any();
}

using (mocks.Playback())
{
IPlugin plugin = new AccountPlugin();
plugin.Execute(context);
}
}



}
}
13. Finally we're ready to run our test. From the Visual Studio menu bar select Test --> Run --> Tests in Current Context.

You should get two passes, as shown in the following screenshot:


Hopefully over the next day or so I'll blog an example of automated unit-testing CRM 2011 plugins.