Tuesday, 20 May 2014

CRM 2011/2013 Know More about Duration Field

In CRM, we can know there is a field data type, that is Whole Number, when you take a look deeper, it has more than 1 available format.


Now, we are talking about Duration format.

When you apply Duration as your Whole Number format, it actually still save number in the Database.


But, when you go to the form and see that you can choose from the Picklist :


It is fine if user can choose from the form by himself.

But, when you come to the backend code and plugin and for example you want to count the Sales Cycle aging by calculation End Date minus Start Date, you have to be aware that the lowest unit is in Minute. It makes your Duration not in Days conversion but in Minutes.

So, make sure that in your plugin you should convert that the Minutes if you want to get duration in Day.
TargetEntity.tfp_Duration = intDuration * 1440;

Here is the result :

In the database :


In the CRM Web


Hope it helps!

1 comment:

  1. Unable to update the Duration field by using plugins.

    Entity retrievedIncident = ServiceObj.Retrieve("incident", relatedIncidentGuid, new ColumnSet(true));
    DateTime createdOn = (DateTime)retrievedIncident.Attributes["createdon"];
    TracingServiceObj.Trace("Case created Date:" + actualEnd);

    TimeSpan totalTimeSpent = actualEnd.Subtract(createdOn);
    TracingServiceObj.Trace("Duration :" + totalTimeSpent.TotalDays);

    Entity incident = new Entity("incident");
    incident.Id = relatedIncidentGuid;
    incident.Attributes["aac_duration"] = totalTimeSpent.TotalMinutes;


My Name is..