Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

Creating service restrictions in plugin

Posted on by 20

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?

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans