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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Delete or Remove Calendar Rule "Time Off Rule" through a plugin or simple console application in C# for CRM 2015

(0) ShareShare
ReportReport
Posted on by

Hello ladies and Gentlemen,

I have the following problem

I need to delete or remove "Time Off Rule" from Calendar Rules of a particular calendar belonging to an "Equipment". This needs to be done so that the equipment is available for scheduling on Service Calendar.

Somehow I cannot understand how to do it. 

I am able to retrieve the Calendar rule object which needs to be deleted but the next step eludes me.
Please be kind enough to let me know

1) Can it be done through C#(SDK)

2) Any web resource or portion of code which does something similar.
The following code gives me the 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); } }


*This post is locked for comments

I have the same question (0)
  • Thusitha Dissanayake Profile Picture
    10 on at
    RE: Delete or Remove Calendar Rule "Time Off Rule" through a plugin or simple console application in C# for CRM 2015

    This is the way to do it.

    http://thusithasblog.blogspot.com/2017/02/deleting-calendar-rules-in-microsoft.html

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans