CRM 4.0: Coverage Dates Contract Acts Like Number of Cases Contract

Lately we’ve discovered an issue with Contracts not allowing users to create an unlimited number of Cases against them, even though the template of the Contracts was set as Coverage Dates.
The behavior could be described as follows:
An active Contract with contract template type Coverage Dates will show contracts lines with the “available number of cases” value set to 1.  As soon as you create and resolve one Case, the “remaining cases” value becomes 0. As a result, no more Cases can be created against the Contact.
To figure out where the issue is coming from and how to fix it – we looked at the way we create our Contracts and what is involved in the process.

Let’s say you’re using a heavily customized Microsoft Dynamic CRM. One of the business requirements you may come across is the need to generate Contracts programmatically. This need might arise via the necessity of integrating CRM with other legacy systems you have or simply to ease the life of your customer service reps by letting them create new Contracts in one click.

Let’s assume you decide to write your plug-in in C# and are using CRM web services API, which is a great customization tool.  You create a VS project, set the web reference to the web service of your CRM installation and you are in business.

Creating a Contract programmatically is very simple (I’m assuming that you’ve already created an instance of CRM service to connect to your CRM server):

First you create an instance of the Contract record and set all required fields:

contract supportContract = new contract();

Required attributes to create a Contract are:

  • activeon
  • billingcustomerid
  • contracttemplateid
  • customerid
  • expireson
  • ownerid
  •  title

Billingstarton and billingendon are required to activate the Contract.

Some background on the types of Contract Templates

To use Contracts you need to create a contract template. To do so you can use one of three different allotment types:

  • Time is an allotment type which allows you to allocate time to be spent on the Contract by service reps. The system will count down time spent on each Case and decrement it until the allowed time is used up. Numeric value  is 1.
  • Number of Cases is an allotment type which allows you to set a fixed number of cases, which are allowed per active contract. Every time a case is being resolved  the system counts down the remaining number of cases on the Contract. Numeric value  is 2.
  • Coverage Dates is an allotment type, which allows you to create an unlimited number of cases against a Contract as long as the Contract is within its activeon and expireson dates.  Numeric value  is 3.

After you set the values of the required attributes, you create your Contract.

TargetCreateContract target = new TargetCreateContract();

target.Contract = supportContract;

CreateRequest create = new CreateRequest();

create.Target = target;

CreateResponse response = (CreateResponse)service.Execute(create);

Guid supportContractGuid = response.id;

Then you need to create your Contract Line Items, or at least one of them, otherwise you will not be able to activate your Contract.

contractdetail tDetail = new contractdetail();

Required attributes are:

  • contractid
  • productid
  • title
  • price
  • activeon
  • expireson

You might want to set customerid, initialquantity and totalallotments.

Then you execute the request of creating contract detail and you are done:

TargetCreateContractDetail targetDetail = new TargetCreateContractDetail();

targetDetail.ContractDetail = tDetail;

CreateRequest createDetail = new CreateRequest();

createDetail.Target = targetDetail;

CreateResponse responseDetail = (CreateResponse)service.Execute(createDetail);

Everything seems to be nice and working until your customer service rep tries to create Cases against this Contract. A Contract that’s been set to use  the Coverage Dates template, starts counting Cases against each Contract line and prevents the poor rep from being able to open the Cases, even though his Customer is entitled to an unlimited number of cases.

The issue lies in the allotmettypecode attribute, which is not required when you create a Contract.  Setting contracttemplateid is supposed to set correct allotmettypecode attribute value, which is 3 for the Coverage Dates contract template.  If you look at the MSDN documentation of the allotmenttypecode attribute it says that value Number of Cases (which is 1) is a default value. This means if you do not set it explicitly the system will set it to 1.

So even though the allotementtypecode is not a required attribute, explicitly setting it to your desired value now will avoid headaches later.

Picklist allType = new Picklist();
allType.Value = 3;
supportContract.allotmenttypecode = allType;

Microsoft has released a kb article detailing how to perform a fix on the system by exporting customization of the Case entity and deleting  AppDefaultValue , which you can read and try here:

The solution did not seem to work on my system, so resorting to the explicit allotmenttypecode value setting is the solution for me at the moment.

Hoping it will help someone out here!

Happy programming!

Related posts: