I have the following problem:
I need to remove or remove the “disconnect rule” from the calendar rules of a specific calendar belonging to the “Equipment”. This must be done so that the equipment is available for planning in Service Calendar.
Somehow I can’t figure out how to do this.
I can get the calendar rule object that needs to be deleted, but the next step eludes me.
Please be so kind as to tell me:
The following code gives me an error
The object you tried to delete is associated with another object and cannot be deleted.
//equip is of Equipment type and is already initialized CrmEarlyBound.Calendar cal = (CrmEarlyBound.Calendar)svc.Retrieve("calendar", equip.CalendarId.Id, new ColumnSet(true)); Console.WriteLine("Got the user calendar"); List<CalendarRule> calendarRules = cal.CalendarRules.ToList(); Console.WriteLine("Got the calendar rules " + cal.CalendarRules.ToList().Count); foreach (CalendarRule cr in cal.CalendarRules) { if (cr.Description == "Time Off Rule" && cr.StartTime.Value>=DateTime.Now) { Console.WriteLine(cr.StartTime); Calendar calI = (Calendar)svc.Retrieve(cr.InnerCalendarId.LogicalName, cr.InnerCalendarId.Id, new ColumnSet(true)); //svc.Delete(cr.InnerCalendarId.LogicalName, cr.InnerCalendarId.Id); } }
source share