Hi,
While creating appointment I don't want to overlap time in between date-time which is already scheduled.
I am using below code to restrict but its not working:
QueryExpression AppointmentQuery = new QueryExpression
{
EntityName = "appointment",
ColumnSet = new ColumnSet(true)
};
FilterExpression filter = new FilterExpression(LogicalOperator.Or);
FilterExpression filter1 = new FilterExpression(LogicalOperator.And);
filter1.Conditions.Add(new ConditionExpression("scheduledstart", ConditionOperator.Equal, _startDate));
filter1.Conditions.Add(new ConditionExpression("scheduledend", ConditionOperator.Equal, _endDate));
filter1.Conditions.Add(new ConditionExpression("cs_meetingroom", ConditionOperator.Equal, MeetingRoomId));
filter1.Conditions.Add(new ConditionExpression("activityid", ConditionOperator.NotEqual, AppointmentSchedule.Id));
FilterExpression filter2 = new FilterExpression(LogicalOperator.And);
filter2.Conditions.Add(new ConditionExpression("scheduledstart", ConditionOperator.LessEqual, _startDate));
filter2.Conditions.Add(new ConditionExpression("scheduledend", ConditionOperator.GreaterEqual, _endDate));
filter2.Conditions.Add(new ConditionExpression("cs_meetingroom", ConditionOperator.Equal, MeetingRoomId));
filter2.Conditions.Add(new ConditionExpression("activityid", ConditionOperator.NotEqual, AppointmentSchedule.Id));
FilterExpression filter3 = new FilterExpression(LogicalOperator.And);
filter3.Conditions.Add(new ConditionExpression("scheduledstart", ConditionOperator.LessThan, _startDate));
filter3.Conditions.Add(new ConditionExpression("scheduledend", ConditionOperator.GreaterThan, _endDate));
filter3.Conditions.Add(new ConditionExpression("cs_meetingroom", ConditionOperator.Equal, MeetingRoomId));
filter3.Conditions.Add(new ConditionExpression("activityid", ConditionOperator.NotEqual, AppointmentSchedule.Id));
FilterExpression filter4 = new FilterExpression(LogicalOperator.And);
filter4.Conditions.Add(new ConditionExpression("scheduledstart", ConditionOperator.LessEqual, _startDate));
filter4.Conditions.Add(new ConditionExpression("scheduledend", ConditionOperator.Equal, _endDate));
filter4.Conditions.Add(new ConditionExpression("cs_meetingroom", ConditionOperator.Equal, MeetingRoomId));
filter4.Conditions.Add(new ConditionExpression("activityid", ConditionOperator.NotEqual, AppointmentSchedule.Id));
FilterExpression filter5 = new FilterExpression(LogicalOperator.And);
filter5.Conditions.Add(new ConditionExpression("scheduledstart", ConditionOperator.Equal, _startDate));
filter5.Conditions.Add(new ConditionExpression("scheduledend", ConditionOperator.LessEqual, _endDate));
filter5.Conditions.Add(new ConditionExpression("cs_meetingroom", ConditionOperator.Equal, MeetingRoomId));
filter5.Conditions.Add(new ConditionExpression("activityid", ConditionOperator.NotEqual, AppointmentSchedule.Id));
FilterExpression filter6 = new FilterExpression(LogicalOperator.And);
filter6.Conditions.Add(new ConditionExpression("scheduledstart", ConditionOperator.LessThan, _startDate));
filter6.Conditions.Add(new ConditionExpression("scheduledstart", ConditionOperator.GreaterThan, _endDate));
filter6.Conditions.Add(new ConditionExpression("cs_meetingroom", ConditionOperator.Equal, MeetingRoomId));
filter6.Conditions.Add(new ConditionExpression("activityid", ConditionOperator.NotEqual, AppointmentSchedule.Id));
FilterExpression filter7 = new FilterExpression(LogicalOperator.And);
filter7.Conditions.Add(new ConditionExpression("scheduledstart", ConditionOperator.GreaterEqual, _startDate));
filter7.Conditions.Add(new ConditionExpression("scheduledend", ConditionOperator.LessEqual, _startDate));
filter7.Conditions.Add(new ConditionExpression("scheduledend", ConditionOperator.GreaterEqual, _endDate));
filter7.Conditions.Add(new ConditionExpression("cs_meetingroom", ConditionOperator.Equal, MeetingRoomId));
filter7.Conditions.Add(new ConditionExpression("activityid", ConditionOperator.NotEqual, AppointmentSchedule.Id));
filter.AddFilter(filter1);
filter.AddFilter(filter2);
filter.AddFilter(filter3);
filter.AddFilter(filter4);
filter.AddFilter(filter5);
filter.AddFilter(filter6);
filter.AddFilter(filter7);
AppointmentQuery.Criteria = filter;
EntityCollection Appointments = service.RetrieveMultiple(AppointmentQuery);
First Appointment:
Second Appointment:
Is there any way to restrict in plugin.
Thanks
*This post is locked for comments