Contracts were the traditional way of recording the entitlements or warranties available to the customer for the product.
Microsoft Dynamics CRM supports 3 types of Contracts
Number of Cases
Draft – This is when you have created a Contract and not yet invoiced the contract
Invoiced – This is when you Invoice the Contract but the Contract Start and End Dates are in the future.
Active – When the Contract start date has passed but is still before the Contract end date
On Hold – You can temporarily suspend the Contract by putting it on hold
Expired – When the Contract End Date has passed.
In CRM it is not easy to find out the contracts that were not renewed, consider a scenario where the service executive has to send an invitation to all the customers who didn’t renewed the contracts.
Here the service executive cannot create a view that will show all the non-renewed contracts from the OOB approach and hence we need to follow the below solution to create a view programmatically for all the non-renewed contracts.
Firstly we need to create the fetchxml to retrieve the non-renewed contracts and then we need to create a view to show these records using the SavedQuery functionality.
var fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
“<entity name=’contract’>” +
“<attribute name=’contractid’ />” +
“<link-entity name=’contract’ from=’originatingcontract’ to=’contractid’ alias=’childcontract’ link-type=’outer’ />” +
“<filter type=’and’>” +
“<condition entityname=’childcontract’ attribute=’originatingcontract’ operator=’null’/>”+
“<condition attribute=’statecode’ operator=’eq’ value=’5′ />” +
In the above query the most important thing to take care is the filter expression applied to remove the renewed contracts from the selection.
Since in this case there is a parental relationship between the original contract and the renewed (New contract created on renewal of the expired contract) contract, so we need to apply the aliased entityname in the filter expression.
After creating the fetchxml we used the SavedQuery feature of CRM to create a view for all the contracts retrieved from the fetchxml above as shown below:
var savedQuery = new SavedQuery()
Name = “All Non-Renewed Contracts”,
ReturnedTypeCode = “contract”,
FetchXml = fetchXml,
QueryType = 0,
We can see the All Non-Renewed Contracts as shown below:
This blog was in response to a query on the forum; however Entitlements are the new enhancements added in Dynamics CRM to overcome the limitations of Contracts and moving forward it would be better to implement Contracts using Entitlements.