C# Code · Dynamics Plugins

Dynamics CRM 365 Capture Case Resolved Date on Case Entity

Currently CRM does not capture Case Resolved Date on Case entity when we resolve cases . We have recieved a requirement from business to capture Resolved Date on case form for analysis and reporting purpose.

CRM System creates Incident Resolution entity record when we close cases in CRM, So I thought of using this entity in OOB workflow. However when I checked workflow we don’t have this entity exposed.

To achieve this business requirement we can use pre operation plugin custom code on Incident Resolution entity.

  1. Create a custom attribute of date type to capture Resolved Date
  2. Register steps on Incident Resolution Create message Pre-operation sync plugin
  3. Copy and paste below code and update attribute name.

Entity objIncidentResolution = context.InputParameters["Target"] as Entity;
                        if (objIncidentResolution.LogicalName != IncidentResolution.EntityLogicalName) return;//Check Entity

                        if (objIncidentResolution != null && service != null)
                        {
                            DateTime dtCreatedOn = DateTime.MinValue;
                            EntityReference erfIncident = null;

                            if(objIncidentResolution.Contains(IncidentResolution.createdonAttribute))
                            {
                                dtCreatedOn = objIncidentResolution.GetAttributeValue(IncidentResolution.createdonAttribute);
                            }

                            if (objIncidentResolution.Contains(IncidentResolution.incidentidAttribute))
                            {
                                erfIncident = objIncidentResolution.GetAttributeValue(IncidentResolution.incidentidAttribute);
                            }
                             
                            if(erfIncident != null && dtCreatedOn > DateTime.MinValue && dtCreatedOn < DateTime.MaxValue)
                            {
                                //Update Incident record
                                Incident objIncidentUpdate = new Incident();
                                objIncidentUpdate.Id = erfIncident.Id;
                                objIncidentUpdate["new_resolutiondate"] = dtCreatedOn;
                                service.Update(objIncidentUpdate);
                            }
                        }

Key Points –

  1. Execution Pipeline should be Pre-Operation otherwise you will get an error “case is already Closed”
  2. Add this attribute on Form, views and use this for reporting and analytics

Hope you find this helpful!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s