Hi.
I have the next task:
When creating service appointment, must be created 2 service restrictions: -1 hour before starttime and +1 hour after endtime to all services, except current(in service appointment), and when update start or end time I must delete previous restrictions and create new.
I'm try to create it by those code:
Entity newInnerCalendar1 = new Entity(); newInnerCalendar1.LogicalName = "calendar"; newInnerCalendar1["businessunitid"] = new EntityReference("businessunit", ((EntityReference)user["businessunitid"]).Id); newInnerCalendar1["primaryuserid"] = user.Id; newInnerCalendar1["type"] = new OptionSetValue(-1); Guid innerCalendarId1 = service.Create(newInnerCalendar1); Entity innerCalendar1 = service.Retrieve("calendar", innerCalendarId1, new ColumnSet(true)); Entity restrictionRule1 = new Entity(); restrictionRule1.LogicalName = "calendarrule"; restrictionRule1["duration"] = 60; restrictionRule1["issimple"] = true; restrictionRule1["offset"] = (serviceappointment.ScheduledStart.Value.Hour - 1) * 60 + serviceappointment.ScheduledStart.Value.Minute; restrictionRule1["rank"] = 0; restrictionRule1["subcode"] = 9;//service restrictions restrictionRule1["timecode"] = 3;//unavailable-filtered restrictionRule1["timezonecode"] = -1; restrictionRule1["serviceid"] = new EntityReference("service", crmService.Id); ((EntityCollection)innerCalendar1["calendarrules"]).Entities.Add(restrictionRule1); service.Update(innerCalendar1);
but:
1)these entires do not apper in user workhours
2)these entires are not counted in the standart service appointment sheduller.
I'm tries to find differrence when creating these records, compared to standard creation of service-restriction in users work-hours, and saw, that wheh i creat it by standart way, in sql-profiler i see 2 more calendar rules, that creates with restriction.
I'm try to add this rules to my plugin, but get error about calendar cycling.
So... what's the way to create service-restrictions in plugin?