0

I wanted to enable custom time calculation for SLA KPIs which is provided in the following link: Enable Custom time calculation of SLA KPIs

However, could you please help me with plugin. I do not understand how to write FetchCalendar method?

if (caseRecord.Attributes.Contains("new_country"))
{
    customCode = (int)(((OptionSetValue)(caseRecord.Attributes["new_country"])).Value);

    // Example 1: Override calendar at runtime: Choose Calendar based on any custom logic
    if (customCode == 0)
    {
        // fetch IST calendar & override CalendarId
        IST_CALENDAR = FetchCalendar("IST_CALENDAR", _service);
        calendarId = IST_CALENDAR;
    }
    else if (customCode == 1)
    {
        // fetch PST calendar & override CalendarId
        PST_CALENDAR = FetchCalendar("PST_CALENDAR", _service);
        calendarId = PST_CALENDAR;
    }       
}

Best Regards, M

AjaV
  • 5
  • 3

1 Answers1

0

Below is kind of Psudeo code, you might have to check with synatx.

private Guid FetchCalendar(string calendarName, OrganizationService _service){
Guid calendarId=Guid.Empty();
// Instantiate QueryExpression query
var query = new QueryExpression("calendar");
// Add all columns to query.ColumnSet
query.ColumnSet.AllColumns = true;
// Define filter query.Criteria
query.Criteria.AddCondition("name", ConditionOperator.Equal, calendarName /* "IST_CALENDAR"*/);
EntityCollection _calendarsCollection = _service.RetrieveMulitple(query);
if(_calendarsCollection.Entities.Count>0){
calendarId =_calendarsCollection.Entities[0].Id;
}
return calendarId;
}
AnkUser
  • 5,421
  • 2
  • 9
  • 25
  • Thanks a lot for the answer. However I am facing an issue with this. I mean, I registered plugin in the following way: Message: Action name, primary Entity: none; and so on... I do not understand, from where plugin gets input parameters? ' string regardingId = context.InputParameters["regardingId"] as string; etc.. I have a problem to debug it. Is it ok to have none for 'Primary Entity' field? How output parameters from plugins knows which entity and which fields to override? I am new so sorry for maybe stupid questions. Regards, M – AjaV Jun 20 '22 at 14:43
  • you will have to dig deeper into how plugins in Dynamics (crm) works and what is context and what it contains and so on. yes you can perfrom debug for plugin as well. Do some google and you will get many articles, but you will have to go step by step – AnkUser Jun 22 '22 at 08:22
  • Hi AnkUser, I succeed to do all of it. Thank you for your support. – AjaV Jun 22 '22 at 09:00