Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Scheduling in CRM 2011 SDK

$
0
0

Hello

I have the following code to schedule a service on a web site, what i want to do is list all the available times in a gridview instead of the way CRM does it.  I.E if i have 2 rooms available from 9AM until 10AM i want them both listed when i select 'ButtonFindTimes' so that i can select either (CRM displays one at a time)

var startTimeInMinutesFromMidnight = int.Parse(this.DDLStartTime.SelectedValue);
            var startDate = this.CalStartDate.SelectedDate.AddMinutes(startTimeInMinutesFromMidnight);
            var endTimeInMinutesFromMidnight = int.Parse(this.DDLEndTime.SelectedValue);
            var endDate = this.CalEndDate.SelectedDate.AddMinutes(endTimeInMinutesFromMidnight);
            if (!SelectedDatesAndTimesAreValid(startDate, endDate, startTimeInMinutesFromMidnight, endTimeInMinutesFromMidnight))
            {
                return;
            }
            var usersMinutesFromGMT = GetUsersMinutesFromGmt(int.Parse(this.DDLTimeZone.SelectedValue));
            var appointmentRequest = new AppointmentRequest
            {
                AnchorOffset = Service.AnchorOffset.GetValueOrDefault(),
                Direction = SearchDirection.Forward,
                Duration = Service.Duration.GetValueOrDefault(60),
                NumberOfResults = 10,
                RecurrenceDuration = endTimeInMinutesFromMidnight - startTimeInMinutesFromMidnight,
                RecurrenceTimeZoneCode = int.Parse(this.DDLTimeZone.SelectedValue),
                SearchRecurrenceRule = "FREQ=DAILY;INTERVAL=1",
                SearchRecurrenceStart = new DateTime(startDate.AddMinutes(usersMinutesFromGMT * -1).Ticks, DateTimeKind.Utc),
                SearchWindowEnd = new DateTime(endDate.AddMinutes(usersMinutesFromGMT * -1).Ticks, DateTimeKind.Utc),
                ServiceId = Service.ServiceId.GetValueOrDefault()
            };
            var service = ServiceContext;
            var searchRequest = new OrganizationRequest("Search");
            searchRequest.Parameters["AppointmentRequest"] = appointmentRequest;
            var searchResults = (SearchResults)service.Execute(searchRequest).Results["SearchResults"];
            var schedules = searchResults.Proposals.Select(proposal => new
            {
                ScheduledStart = proposal.Start.GetValueOrDefault().ToUniversalTime().AddMinutes(usersMinutesFromGMT),
                ScheduledStartUniversalTime = proposal.Start.GetValueOrDefault().ToUniversalTime(),
                ScheduledEnd = proposal.End.GetValueOrDefault().ToUniversalTime().AddMinutes(usersMinutesFromGMT),
                ScheduledEndUniversalTime = proposal.End.GetValueOrDefault().ToUniversalTime(),
                AvailableResource = proposal.ProposalParties.First().ResourceId
            });
            this.GridViewAvailableTimes.DataSource = schedules;
            this.GridViewAvailableTimes.DataBind();

Many thanks

Duane


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>