web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Unable to get onholdtime field of incident on close message from plugin

(0) ShareShare
ReportReport
Posted on by 458

Hi there all experts.
I am brand new to write crm plugins, but I am trying to do my best.
I have written a plugin on preopration stage , on close message of incident.

I know I should get incident record from incident resolution record.

I can retrieve other fields of incident according to the below code, but I can not get onholdtime field( duration of being on-hold in minute )of incident.
Here is the code I retrieve and display createdon field.

            IPluginExecutionContext context = (IPluginExecutionContext)
               serviceProvider.GetService(typeof(IPluginExecutionContext));
            // Get a reference to the Organization service.
            IOrganizationServiceFactory servicefactory =
                (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = servicefactory.CreateOrganizationService(context.UserId);
            DateTime actualEnd = DateTime.Now;
            if (context.InputParameters.Contains("IncidentResolution"))
            {
                Entity incidentResolution = (Entity)context.InputParameters["IncidentResolution"];
                Guid guid = ((EntityReference)incidentResolution.Attributes["incidentid"]).Id;
                if (incidentResolution.Contains("actualend"))
                {
                    actualEnd = (DateTime)incidentResolution.Attributes["actualend"];
                }
                Entity retrievedIncident = service.Retrieve("incident", guid, new ColumnSet("ms_resolvedatetime", "createdon", "onholdtime"));
                DateTime createdOn = (DateTime) retrievedIncident.Attributes["createdon"];
                // int onHoldInMinute = (int) retrievedIncident.Attributes["onholdtime"];
                retrievedIncident.Attributes["ms_resolvedatetime"] = actualEnd;
                throw new
                     InvalidPluginExecutionException(string.Format("createdon: {0}",
                     createdOn.ToString()));

It returns the createdon field value via throwing an exception.

But when I uncomment the line :

int onHoldInMinute = (int) retrievedIncident.Attributes["onholdtime"];

I give me this error, with meaning that there is no field with this key/name.

<Message>System.Collections.Generic.KeyNotFoundException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #2D66D0C6</Message>

This message is like the plugin can not find the onholdtime,
what is wrong?

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 101 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 72

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans